[Telepathy-commits] [telepathy-gabble/master] start to implement joined message stanza

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Sep 26 10:02:23 PDT 2008


20080627225907-7fe3f-051b7f3d56f42273adc1c551639dc837df0f7e52.gz
---
 src/conn-olpc.c                            |   75 ++++++++++++++++++++++++++-
 tests/twisted/olpc/olpc-activity-search.py |   32 ++++++++++++
 2 files changed, 104 insertions(+), 3 deletions(-)

diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index 8986b56..3c6f4d8 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -3061,6 +3061,7 @@ activity_changed (GabbleConnection *conn,
 static gboolean
 populate_buddies_from_nodes (GabbleConnection *conn,
                              LmMessageNode *node,
+                             const gchar *node_name,
                              GArray *buddies,
                              GPtrArray *buddies_properties)
 {
@@ -3075,7 +3076,7 @@ populate_buddies_from_nodes (GabbleConnection *conn,
       GHashTable *properties;
       TpHandle handle;
 
-      if (tp_strdiff (buddy->name, "buddy"))
+      if (tp_strdiff (buddy->name, node_name))
         continue;
 
       jid = lm_message_node_get_attribute (buddy, "jid");
@@ -3191,7 +3192,7 @@ add_activities_to_view_from_node (GabbleConnection *conn,
       buddies = g_array_new (FALSE, FALSE, sizeof (TpHandle));
       buddies_properties = g_ptr_array_new ();
 
-      if (!populate_buddies_from_nodes (conn, activity_node, buddies,
+      if (!populate_buddies_from_nodes (conn, activity_node, "buddy", buddies,
             buddies_properties))
         {
           g_array_free (buddies, TRUE);
@@ -3249,7 +3250,8 @@ add_buddies_to_view_from_node (GabbleConnection *conn,
   buddies = g_array_new (FALSE, FALSE, sizeof (TpHandle));
   buddies_properties = g_ptr_array_new ();
 
-  if (!populate_buddies_from_nodes (conn, node, buddies, buddies_properties))
+  if (!populate_buddies_from_nodes (conn, node, "buddy", buddies,
+        buddies_properties))
     {
       g_array_free (buddies, TRUE);
       g_ptr_array_free (buddies_properties, TRUE);
@@ -3430,6 +3432,68 @@ activity_removed (GabbleConnection *conn,
   remove_activities_from_view_from_node (conn, view, removed);
 }
 
+static void
+activity_membership_change (GabbleConnection *conn,
+                            LmMessageNode *activity_node)
+{
+  const gchar *id_str;
+  guint id;
+  GabbleOlpcView *view;
+  GArray *buddies;
+  GPtrArray *buddies_properties;
+  TpHandle handle;
+  const gchar *room;
+  TpHandleRepoIface *room_repo = tp_base_connection_get_handles (
+      (TpBaseConnection *) conn, TP_HANDLE_TYPE_ROOM);
+
+  id_str = lm_message_node_get_attribute (activity_node, "id");
+  if (id_str == NULL)
+    return;
+
+  id = strtoul (id_str, NULL, 10);
+  view = g_hash_table_lookup (conn->olpc_views, GUINT_TO_POINTER (id));
+  if (view == NULL)
+    {
+      DEBUG ("no view with ID %u", id);
+      return;
+    }
+
+  room = lm_message_node_get_attribute (activity_node, "room");
+  if (room == NULL)
+    {
+      DEBUG ("no room attribute");
+      return;
+    }
+
+  handle = tp_handle_ensure (room_repo, room, NULL, NULL);
+  if (handle == 0)
+    {
+      DEBUG ("Invalid room handle");
+      return;
+    }
+
+  /* joined buddies */
+  buddies = g_array_new (FALSE, FALSE, sizeof (TpHandle));
+  buddies_properties = g_ptr_array_new ();
+
+  if (!populate_buddies_from_nodes (conn, activity_node, "joined", buddies,
+        buddies_properties))
+    {
+      g_array_free (buddies, TRUE);
+      g_ptr_array_free (buddies_properties, TRUE);
+      tp_handle_unref (room_repo, handle);
+      return;
+    }
+
+  /* FIXME: use add_buddies_to_view_from_node instead? */
+  /* FIXME: free ressources allocated in populate_buddies_from_nodes */
+  gabble_olpc_view_add_buddies (view, buddies, buddies_properties, handle);
+
+  /* TODO: left and closed */
+
+  tp_handle_unref (room_repo, handle);
+}
+
 LmHandlerResult
 conn_olpc_msg_cb (LmMessageHandler *handler,
                   LmConnection *connection,
@@ -3495,6 +3559,11 @@ conn_olpc_msg_cb (LmMessageHandler *handler,
         {
           activity_removed (conn, node);
         }
+      else if (!tp_strdiff (node->name, "activity") &&
+          !tp_strdiff (ns, NS_OLPC_ACTIVITY))
+        {
+          activity_membership_change (conn, node);
+        }
       /* TODO: join, left and closed announcements */
     }
 
diff --git a/tests/twisted/olpc/olpc-activity-search.py b/tests/twisted/olpc/olpc-activity-search.py
index acbada1..6491c85 100644
--- a/tests/twisted/olpc/olpc-activity-search.py
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -346,6 +346,38 @@ def test(q, bus, conn, stream):
     props = activity_prop_iface.GetProperties(room)
     assert props == {'tags': 'game', 'color': '#AABBAA,#BBAABB'}
 
+    # a new buddy joins the activity
+    message = domish.Element(('jabber:client', 'message'))
+    message['from'] = 'gadget.localhost'
+    message['to'] = 'alice at localhost'
+    message['type'] = 'notice'
+
+    activity = message.addElement((NS_OLPC_ACTIVITY, 'activity'))
+    activity['room'] = 'testactivity at conference.localhost'
+    activity['id'] = '0'
+    joined = activity.addElement((None, 'joined'))
+    joined['jid'] = 'marcel at localhost'
+    properties = joined.addElement((NS_OLPC_BUDDY_PROPS, "properties"))
+    property = properties.addElement((None, "property"))
+    property['type'] = 'str'
+    property['name'] = 'color'
+    property.addContent('#CCCCCC,#DDDDDD')
+
+    amp = message.addElement((NS_AMP, 'amp'))
+    rule = amp.addElement((None, 'rule'))
+    rule['condition'] = 'deliver-at'
+    rule['value'] = 'stored'
+    rule['action'] ='error'
+    print "-------------------------"
+    stream.send(message)
+
+    # FIXME: BuddyInfo.PropertiesChanged
+    # FIXME: BuddyInfo.ActivitiesChanged
+
+    event = q.expect('dbus-signal', signal='BuddiesChanged')
+    added, removed = event.args
+    assert conn.InspectHandles(1, added) == ['marcel at localhost']
+
     # remove one activity from view 0
     message = domish.Element((None, 'message'))
     message['from'] = 'gadget.localhost'
-- 
1.5.6.5




More information about the Telepathy-commits mailing list