[Telepathy-commits] [telepathy-gabble/master] fire BuddyInfo.ActivitiesChanged when activity views are changed

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


20080701095619-7fe3f-865efb2cc381f65c4ccd1739106ae651f32ba357.gz
---
 src/conn-olpc.c                            |   20 ++++++++++++
 src/olpc-view.c                            |   24 +++++++++++++-
 tests/twisted/olpc/olpc-activity-search.py |   47 +++++++++++++++++++--------
 3 files changed, 76 insertions(+), 15 deletions(-)

diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index 56f7c04..7f06bc7 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -3673,6 +3673,23 @@ view_closed_cb (GabbleOlpcView *view,
   g_hash_table_remove (conn->olpc_views, GUINT_TO_POINTER (id));
 }
 
+static void
+buddy_activities_changed_cb (GabbleOlpcView *view,
+                             TpHandle contact,
+                             GabbleConnection *conn)
+{
+  GPtrArray *activities;
+
+  /* FIXME: this is not optimal as we completely ignore PEP-announced
+   * activities. Ideally we should cache PEP activities. */
+  activities = find_buddy_activities_from_views (conn, contact);
+
+  gabble_svc_olpc_buddy_info_emit_activities_changed (conn, contact,
+      activities);
+
+  free_activities (activities);
+}
+
 static GabbleOlpcView *
 create_view (GabbleConnection *conn,
              GabbleOlpcViewType type)
@@ -3696,6 +3713,9 @@ create_view (GabbleConnection *conn,
 
   g_signal_connect (view, "closed", G_CALLBACK (view_closed_cb), conn);
 
+  g_signal_connect (view, "buddy-activities-changed",
+      G_CALLBACK (buddy_activities_changed_cb), conn);
+
   return view;
 }
 
diff --git a/src/olpc-view.c b/src/olpc-view.c
index 2b8ae19..fcd3130 100644
--- a/src/olpc-view.c
+++ b/src/olpc-view.c
@@ -41,6 +41,7 @@
 enum
 {
   CLOSED,
+  BUDDY_ACTIVITIES_CHANGED,
   LAST_SIGNAL
 };
 
@@ -313,6 +314,15 @@ gabble_olpc_view_class_init (GabbleOlpcViewClass *gabble_olpc_view_class)
         NULL, NULL,
         gabble_marshal_VOID__VOID,
         G_TYPE_NONE, 0);
+
+  signals[BUDDY_ACTIVITIES_CHANGED] =
+    g_signal_new ("buddy-activities-changed",
+        G_OBJECT_CLASS_TYPE (gabble_olpc_view_class),
+        G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
+        0,
+        NULL, NULL,
+        gabble_marshal_VOID__UINT,
+        G_TYPE_NONE, 1, G_TYPE_UINT);
 }
 
 GabbleOlpcView *
@@ -492,7 +502,13 @@ gabble_olpc_view_add_buddies (GabbleOlpcView *self,
                     handle), set);
             }
 
-          tp_handle_set_add (set, room);
+          if (!tp_handle_set_is_member (set, room))
+            {
+              tp_handle_set_add (set, room);
+
+              g_signal_emit (G_OBJECT (self),
+                  signals[BUDDY_ACTIVITIES_CHANGED], 0, handle);
+            }
         }
     }
 
@@ -604,6 +620,9 @@ remove_activity_foreach_buddy (TpHandle buddy,
           /* No more activity for this buddy. Remove it */
           tp_handle_set_add (ctx->removed, buddy);
         }
+
+      g_signal_emit (G_OBJECT (ctx->view), signals[BUDDY_ACTIVITIES_CHANGED],
+          0, buddy);
     }
 }
 
@@ -737,6 +756,9 @@ gabble_olpc_view_buddies_left_activity (GabbleOlpcView *self,
               /* Remove from the view */
               tp_handle_set_add (removed, buddy);
             }
+
+          g_signal_emit (G_OBJECT (self), signals[BUDDY_ACTIVITIES_CHANGED],
+              0, buddy);
         }
     }
 
diff --git a/tests/twisted/olpc/olpc-activity-search.py b/tests/twisted/olpc/olpc-activity-search.py
index 2a6e4bf..88c2605 100644
--- a/tests/twisted/olpc/olpc-activity-search.py
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -405,10 +405,10 @@ def test(q, bus, conn, stream):
     # view 1: activity 2
     # view 2: activity 3
 
-    # FIXME: BuddyInfo.ActivitiesChanged
-    view_event, buddy_info_event = q.expect_many(
+    view_event, buddy_info_event, activities_changed_event = q.expect_many(
             EventPattern('dbus-signal', signal='BuddiesChanged'),
-            EventPattern('dbus-signal', signal='PropertiesChanged'))
+            EventPattern('dbus-signal', signal='PropertiesChanged'),
+            EventPattern('dbus-signal', signal='ActivitiesChanged'))
 
     added, removed = view_event.args
     assert conn.InspectHandles(1, added) == ['marcel at localhost']
@@ -423,6 +423,10 @@ def test(q, bus, conn, stream):
         ['fernand at localhost', 'lucien at localhost', 'jean at localhost',
             'marcel at localhost'])
 
+    contact, activities = activities_changed_event.args
+    assert contact == added[0]
+    assert activities == [('activity1', room1_handle)]
+
     # Marcel left activity 1
     message = domish.Element(('jabber:client', 'message'))
     message['from'] = 'gadget.localhost'
@@ -447,15 +451,19 @@ def test(q, bus, conn, stream):
     # view 1: activity 2
     # view 2: activity 3
 
-    # FIXME: BuddyInfo.ActivitiesChanged
-    view_event = q.expect_many(
-            EventPattern('dbus-signal', signal='BuddiesChanged'))
+    view_event, activities_changed_event = q.expect_many(
+            EventPattern('dbus-signal', signal='BuddiesChanged'),
+            EventPattern('dbus-signal', signal='ActivitiesChanged'))
 
     # check activities and buddies in view
     check_view(view0_iface, conn, [
         ('activity1', room1_handle),('activity4', room4_handle)],
         ['fernand at localhost', 'lucien at localhost', 'jean at localhost'])
 
+    contact, activities = activities_changed_event.args
+    assert conn.InspectHandles(1, [contact]) == ['marcel at localhost']
+    assert activities == []
+
     # Jean left activity 1
     message = domish.Element(('jabber:client', 'message'))
     message['from'] = 'gadget.localhost'
@@ -480,6 +488,11 @@ def test(q, bus, conn, stream):
     # view 1: activity 2
     # view 2: activity 3
 
+    activities_changed_event = q.expect('dbus-signal',
+            signal='ActivitiesChanged')
+    contact, activities = activities_changed_event.args
+    assert conn.InspectHandles(1, [contact]) == ['jean at localhost']
+
     # Jean wasn't removed from the view as he is still in activity 4
     check_view(view0_iface, conn, [
         ('activity1', room1_handle),('activity4', room4_handle)],
@@ -507,18 +520,24 @@ def test(q, bus, conn, stream):
     # view 1: activity 2
     # view 2: activity 3
 
+    buddies_changed_event, _, buddies_activities_changed_event = \
+            q.expect_many(
+            EventPattern('dbus-signal', signal='BuddiesChanged'),
+    # activity is removed from the view
+            EventPattern('dbus-signal', signal='ActivitiesChanged',
+                interface='org.laptop.Telepathy.View',
+                args=[[], [('activity1', room1_handle)]]),
+            EventPattern('dbus-signal', signal='ActivitiesChanged',
+                interface='org.laptop.Telepathy.BuddyInfo'))
+
     # participants are removed from the view
-    event = q.expect('dbus-signal', signal='BuddiesChanged')
-    added, removed = event.args
+    added, removed = buddies_changed_event.args
     assert sorted(conn.InspectHandles(1, removed)) == \
             sorted(['lucien at localhost'])
-    # FIXME: BuddyInfo.ActivitiesChanged
 
-    # activity is removed
-    event = q.expect('dbus-signal', signal='ActivitiesChanged')
-    added, removed = event.args
-    assert added == []
-    assert removed == [('activity1', room1_handle)]
+    contact, activities = buddies_activities_changed_event.args
+    assert contact == removed[0]
+    assert activities == []
 
     # check activities and buddies in view
     check_view(view0_iface, conn, [
-- 
1.5.6.5




More information about the Telepathy-commits mailing list