[Telepathy-commits] [telepathy-gabble/master] remove buddies from existing views
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Sep 26 10:02:09 PDT 2008
20080522110540-7fe3f-5e73e2f0fabff8540ad4b3b8a09ce5a5c86280cc.gz
---
src/conn-olpc.c | 69 +++++++++++++++++++++++++++++++
src/olpc-buddy-view.c | 15 +++++++
src/olpc-buddy-view.h | 4 ++
tests/twisted/olpc/olpc-buddy-search.py | 29 ++++++++++++-
4 files changed, 116 insertions(+), 1 deletions(-)
diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index e4ffae3..07d05fe 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -2938,6 +2938,70 @@ buddy_added (GabbleConnection *conn,
add_buddies_to_view_from_node (conn, view, added);
}
+static gboolean
+remove_buddies_from_view_from_node (GabbleConnection *conn,
+ GabbleOlpcBuddyView *view,
+ LmMessageNode *node)
+{
+ TpHandleSet *buddies;
+ TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
+ (TpBaseConnection*) conn, TP_HANDLE_TYPE_CONTACT);
+ LmMessageNode *buddy;
+
+ buddies = tp_handle_set_new (contact_repo);
+
+ for (buddy = node->children; buddy != NULL; buddy = buddy->next)
+ {
+
+ const gchar *jid;
+ TpHandle handle;
+
+ if (tp_strdiff (buddy->name, "buddy"))
+ continue;
+
+ jid = lm_message_node_get_attribute (buddy, "jid");
+
+ handle = tp_handle_ensure (contact_repo, jid, NULL, NULL);
+ if (handle == 0)
+ {
+ DEBUG ("Invalid jid: %s", jid);
+ tp_handle_set_destroy (buddies);
+ return FALSE;
+ }
+
+ tp_handle_set_add (buddies, handle);
+ tp_handle_unref (contact_repo, handle);
+ }
+
+ gabble_olpc_buddy_view_remove_buddies (view, buddies);
+ tp_handle_set_destroy (buddies);
+
+ return TRUE;
+}
+
+static void
+buddy_removed (GabbleConnection *conn,
+ LmMessageNode *removed)
+{
+ const gchar *id_str;
+ guint id;
+ GabbleOlpcBuddyView *view;
+
+ id_str = lm_message_node_get_attribute (removed, "id");
+ if (id_str == NULL)
+ return;
+
+ id = strtoul (id_str, NULL, 10);
+ view = g_hash_table_lookup (conn->olpc_buddy_views, GUINT_TO_POINTER (id));
+ if (view == NULL)
+ {
+ DEBUG ("no buddy view with ID %u", id);
+ return;
+ }
+
+ remove_buddies_from_view_from_node (conn, view, removed);
+}
+
LmHandlerResult
conn_olpc_msg_cb (LmMessageHandler *handler,
LmConnection *connection,
@@ -2989,6 +3053,11 @@ conn_olpc_msg_cb (LmMessageHandler *handler,
{
buddy_added (conn, node);
}
+ else if (!tp_strdiff (node->name, "removed") &&
+ !tp_strdiff (ns, NS_OLPC_BUDDY))
+ {
+ buddy_removed (conn, node);
+ }
}
return LM_HANDLER_RESULT_REMOVE_MESSAGE;
diff --git a/src/olpc-buddy-view.c b/src/olpc-buddy-view.c
index c65aa78..47b94cb 100644
--- a/src/olpc-buddy-view.c
+++ b/src/olpc-buddy-view.c
@@ -335,6 +335,21 @@ gabble_olpc_buddy_view_add_buddies (GabbleOlpcBuddyView *self,
tp_intset_destroy (empty);
}
+void
+gabble_olpc_buddy_view_remove_buddies (GabbleOlpcBuddyView *self,
+ TpHandleSet *buddies)
+{
+ TpIntSet *empty;
+
+ empty = tp_intset_new ();
+
+ tp_group_mixin_change_members (G_OBJECT (self), "",
+ empty, tp_handle_set_peek (buddies), empty, empty,
+ 0, TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
+
+ tp_intset_destroy (empty);
+}
+
static void
buddy_view_iface_init (gpointer g_iface,
gpointer iface_data)
diff --git a/src/olpc-buddy-view.h b/src/olpc-buddy-view.h
index e5ea426..2724fa5 100644
--- a/src/olpc-buddy-view.h
+++ b/src/olpc-buddy-view.h
@@ -71,6 +71,10 @@ GabbleOlpcBuddyView * gabble_olpc_buddy_view_new (GabbleConnection *conn,
void gabble_olpc_buddy_view_add_buddies (GabbleOlpcBuddyView *self,
TpHandleSet *handles);
+
+void gabble_olpc_buddy_view_remove_buddies (GabbleOlpcBuddyView *self,
+ TpHandleSet *handles);
+
G_END_DECLS
#endif /* #ifndef __GABBLE_OLPC_BUDDY_VIEW_H__ */
diff --git a/tests/twisted/olpc/olpc-buddy-search.py b/tests/twisted/olpc/olpc-buddy-search.py
index bc49fde..bdff05d 100644
--- a/tests/twisted/olpc/olpc-buddy-search.py
+++ b/tests/twisted/olpc/olpc-buddy-search.py
@@ -199,7 +199,7 @@ def test(q, bus, conn, stream):
handle = added[0]
assert conn.InspectHandles(1, [handle])[0] == 'charles at localhost'
- # add A buddy to view 0
+ # add a buddy to view 0
message = domish.Element((None, 'message'))
message['from'] = 'gadget.localhost'
message['to'] = 'alice at localhost'
@@ -231,6 +231,33 @@ def test(q, bus, conn, stream):
members = sorted(conn.InspectHandles(1, members))
assert members == ['bob at localhost', 'oscar at localhost']
+ # remove a buddy from view 0
+ message = domish.Element((None, 'message'))
+ message['from'] = 'gadget.localhost'
+ message['to'] = 'alice at localhost'
+ message['type'] = 'notice'
+ added = message.addElement((NS_OLPC_BUDDY, 'removed'))
+ added['id'] = '0'
+ buddy = added.addElement((None, 'buddy'))
+ buddy['jid'] = 'bob at localhost'
+ amp = message.addElement((NS_AMP, 'amp'))
+ rule = amp.addElement((None, 'rule'))
+ rule['condition'] = 'deliver-at'
+ rule['value'] = 'stored'
+ rule['action'] ='error'
+ stream.send(message)
+
+ event = q.expect('dbus-signal', signal='MembersChanged')
+ msg, added, removed, lp, rp, actor, reason = event.args
+ assert (added, lp, rp) == ([], [], [])
+ assert len(removed) == 1
+ handle = removed[0]
+ assert conn.InspectHandles(1, [handle])[0] == 'bob at localhost'
+
+ members = view0_group_iface.GetMembers()
+ members = sorted(conn.InspectHandles(1, members))
+ assert members == ['oscar at localhost']
+
# close view 0
call_async(q, view0_iface, 'Close')
event, _ = q.expect_many(
--
1.5.6.5
More information about the Telepathy-commits
mailing list