[Telepathy-commits] [telepathy-gabble/master] add activities to view *before* their participants so the BuddyInfo.ActivitiesChanged signal is fired with these activities too

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


20080723135804-7fe3f-230960b1310f0c7437657ca215910181fb284f5e.gz
---
 src/conn-olpc.c                            |   37 ++++++++++++++++++++++++--
 tests/twisted/olpc/olpc-activity-search.py |   39 ++++++++++++++++++++++-----
 2 files changed, 65 insertions(+), 11 deletions(-)

diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index f5001d7..f2caba1 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -3093,10 +3093,20 @@ add_activities_to_view_from_node (GabbleConnection *conn,
       (TpBaseConnection *) conn, TP_HANDLE_TYPE_ROOM);
   GHashTable *activities;
   LmMessageNode *activity_node;
+  GPtrArray *buddies_to_add;
+  struct buddies_to_add_t
+    {
+      GArray *buddies;
+      GPtrArray *buddies_properties;
+      TpHandle room;
+    };
+  guint i;
 
   activities = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
       g_object_unref );
 
+  buddies_to_add = g_ptr_array_new ();
+
   for (activity_node = node->children; activity_node != NULL;
       activity_node = activity_node->next)
     {
@@ -3107,6 +3117,7 @@ add_activities_to_view_from_node (GabbleConnection *conn,
       GabbleOlpcActivity *activity;
       GArray *buddies;
       GPtrArray *buddies_properties;
+      struct buddies_to_add_t *tmp;
 
       jid = lm_message_node_get_attribute (activity_node, "room");
       if (jid == NULL)
@@ -3173,14 +3184,34 @@ add_activities_to_view_from_node (GabbleConnection *conn,
           continue;
         }
 
-      gabble_olpc_view_add_buddies (view, buddies, buddies_properties, handle);
+      /* We have to wait that activities were added to the view before
+       * adding participants */
+      tmp = g_slice_new (struct buddies_to_add_t);
+      tmp->buddies = buddies;
+      tmp->buddies_properties = buddies_properties;
+      tmp->room = handle;
 
-      g_array_free (buddies, TRUE);
-      g_ptr_array_free (buddies_properties, TRUE);
+      g_ptr_array_add (buddies_to_add, tmp);
     }
 
   gabble_olpc_view_add_activities (view, activities);
 
+  /* Add participants to the view */
+  for (i = 0; i < buddies_to_add->len; i++)
+    {
+      struct buddies_to_add_t *tmp;
+
+      tmp = g_ptr_array_index (buddies_to_add, i);
+
+      gabble_olpc_view_add_buddies (view, tmp->buddies,
+          tmp->buddies_properties, tmp->room);
+
+      g_array_free (tmp->buddies, TRUE);
+      g_ptr_array_free (tmp->buddies_properties, TRUE);
+      g_slice_free (struct buddies_to_add_t, tmp);
+    }
+
+  g_ptr_array_free (buddies_to_add, TRUE);
   g_hash_table_destroy (activities);
 
   return TRUE;
diff --git a/tests/twisted/olpc/olpc-activity-search.py b/tests/twisted/olpc/olpc-activity-search.py
index 01a8517..437e86c 100644
--- a/tests/twisted/olpc/olpc-activity-search.py
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -85,14 +85,23 @@ def test(q, bus, conn, stream):
             'room1 at conference.localhost'
     assert props == {'color': '#005FE4,#00A0FF'}
 
-    # participants are added to view
-    q.expect('dbus-signal', signal='BuddiesChanged',
-            args=[[handles['lucien'], handles['jean']], []])
-
     q.expect('dbus-signal', signal='ActivitiesChanged',
             interface='org.laptop.Telepathy.View',
             args=[[('activity1', handles['room1'])], []])
 
+    # participants are added to activity
+    q.expect_many(
+        EventPattern('dbus-signal', signal='ActivitiesChanged',
+            interface='org.laptop.Telepathy.BuddyInfo',
+            args=[handles['lucien'], [('activity1', handles['room1'])]]),
+        EventPattern('dbus-signal', signal='ActivitiesChanged',
+            interface='org.laptop.Telepathy.BuddyInfo',
+            args=[handles['jean'], [('activity1', handles['room1'])]]))
+
+    # participants are added to view
+    q.expect('dbus-signal', signal='BuddiesChanged',
+            args=[[handles['lucien'], handles['jean']], []])
+
     # check activities and buddies in view
     check_view(view0_iface, conn, [('activity1', handles['room1'])],
             ['lucien at localhost', 'jean at localhost'])
@@ -243,10 +252,7 @@ def test(q, bus, conn, stream):
 
     handles['fernand'] = conn.RequestHandles(1, ['fernand at localhost',])[0]
 
-    q.expect('dbus-signal', signal='BuddiesChanged',
-            args=[[handles['fernand'], handles['jean']], []])
-
-    # activity is added too
+    # activity is added
     event = q.expect('dbus-signal', signal='ActivitiesChanged',
             interface='org.laptop.Telepathy.View')
     added, removed = event.args
@@ -256,11 +262,28 @@ def test(q, bus, conn, stream):
     assert sorted(conn.InspectHandles(2, [handles['room4']])) == \
             ['room4 at conference.localhost']
 
+    # buddies are added to activity
+    q.expect_many(
+        EventPattern('dbus-signal', signal='ActivitiesChanged',
+            interface='org.laptop.Telepathy.BuddyInfo',
+            args=[handles['fernand'], [('activity4', handles['room4'])]]),
+        EventPattern('dbus-signal', signal='ActivitiesChanged',
+            interface='org.laptop.Telepathy.BuddyInfo',
+            args=[handles['jean'], [('activity1', handles['room1']),
+                ('activity4', handles['room4'])]]))
+
+    q.expect('dbus-signal', signal='BuddiesChanged',
+            args=[[handles['fernand'], handles['jean']], []])
+
     # check activities and buddies in view
     check_view(view0_iface, conn, [
         ('activity1', handles['room1']), ('activity4', handles['room4'])],
         ['fernand at localhost', 'lucien at localhost', 'jean at localhost'])
 
+    # check activity's properties
+    props = activity_prop_iface.GetProperties(handles['room4'])
+    assert props == {'color': '#DDEEDD,#EEDDEE'}
+
     # Gadget informs us about an activity properties change
     message = domish.Element(('jabber:client', 'message'))
     message['from'] = 'gadget.localhost'
-- 
1.5.6.5




More information about the Telepathy-commits mailing list