[Telepathy-commits] [telepathy-gabble/master] manage "buddy left activity" message from Gadget

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


20080630135548-7fe3f-b34938fa72a053f844b21ef8996589449eebbae8.gz
---
 src/conn-olpc.c                            |   40 ++++++++++++++++++++++++--
 src/olpc-view.c                            |   43 ++++++++++++++++++++++++++++
 src/olpc-view.h                            |    3 ++
 tests/twisted/olpc/olpc-activity-search.py |   23 +++++++++++++++
 4 files changed, 106 insertions(+), 3 deletions(-)

diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index d298816..56f7c04 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -3092,8 +3092,11 @@ populate_buddies_from_nodes (GabbleConnection *conn,
             tp_handle_unref (contact_repo, g_array_index (buddies, TpHandle,
                   i));
 
-          g_ptr_array_foreach (buddies_properties, (GFunc) g_hash_table_unref,
-              NULL);
+          if (buddies_properties != NULL)
+            {
+              g_ptr_array_foreach (buddies_properties,
+                  (GFunc) g_hash_table_unref, NULL);
+            }
 
           return FALSE;
         }
@@ -3105,7 +3108,10 @@ populate_buddies_from_nodes (GabbleConnection *conn,
       properties = lm_message_node_extract_properties (properties_node,
           "property");
 
-      g_ptr_array_add (buddies_properties, properties);
+      if (buddies_properties != NULL)
+        {
+          g_ptr_array_add (buddies_properties, properties);
+        }
     }
 
   return TRUE;
@@ -3447,6 +3453,30 @@ activity_removed (GabbleConnection *conn,
   remove_activities_from_view_from_node (conn, view, removed);
 }
 
+static gboolean
+remove_buddies_from_activity_view (GabbleConnection *conn,
+                                   GabbleOlpcView *view,
+                                   LmMessageNode *node,
+                                   const gchar *node_name,
+                                   TpHandle room)
+{
+  GArray *buddies;
+
+  buddies = g_array_new (FALSE, FALSE, sizeof (TpHandle));
+
+  if (!populate_buddies_from_nodes (conn, node, node_name, buddies,
+        NULL))
+    {
+      g_array_free (buddies, TRUE);
+      return FALSE;
+    }
+
+  gabble_olpc_view_buddies_left_activity (view, buddies, room);
+
+  g_array_free (buddies, TRUE);
+  return TRUE;
+}
+
 static void
 activity_membership_change (GabbleConnection *conn,
                             LmMessageNode *activity_node)
@@ -3488,6 +3518,10 @@ activity_membership_change (GabbleConnection *conn,
   /* joined buddies */
   add_buddies_to_view_from_node (conn, view, activity_node, "joined", handle);
 
+  /* left buddies */
+  remove_buddies_from_activity_view (conn, view, activity_node, "left",
+      handle);
+
   /* TODO: left and closed */
 
   tp_handle_unref (room_repo, handle);
diff --git a/src/olpc-view.c b/src/olpc-view.c
index a1308b2..2b8ae19 100644
--- a/src/olpc-view.c
+++ b/src/olpc-view.c
@@ -705,6 +705,49 @@ gabble_olpc_view_get_buddy_activities (GabbleOlpcView *self,
   return activities;
 }
 
+void
+gabble_olpc_view_buddies_left_activity (GabbleOlpcView *self,
+                                        GArray *buddies,
+                                        TpHandle room)
+{
+  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  guint i;
+  TpHandleRepoIface *contact_repo;
+  TpHandleSet *removed;
+
+  contact_repo = tp_base_connection_get_handles (
+      (TpBaseConnection *) priv->conn, TP_HANDLE_TYPE_CONTACT);
+
+  removed = tp_handle_set_new (contact_repo);
+
+  for (i = 0; i < buddies->len; i++)
+    {
+      TpHandleSet *set;
+      TpHandle buddy;
+
+      buddy = g_array_index (buddies, TpHandle, i);
+      set = g_hash_table_lookup (priv->buddy_rooms, GUINT_TO_POINTER (buddy));
+      if (set == NULL)
+        continue;
+
+      if (tp_handle_set_remove (set, room))
+        {
+          if (tp_handle_set_size (set) == 0)
+            {
+              /* Remove from the view */
+              tp_handle_set_add (removed, buddy);
+            }
+        }
+    }
+
+  if (tp_handle_set_size (removed) > 0)
+    {
+      gabble_olpc_view_remove_buddies (self, removed);
+    }
+
+  tp_handle_set_destroy (removed);
+}
+
 static void
 view_iface_init (gpointer g_iface,
                  gpointer iface_data)
diff --git a/src/olpc-view.h b/src/olpc-view.h
index ae68910..0951795 100644
--- a/src/olpc-view.h
+++ b/src/olpc-view.h
@@ -91,6 +91,9 @@ void gabble_olpc_view_remove_activities (GabbleOlpcView *self,
 GPtrArray * gabble_olpc_view_get_buddy_activities (GabbleOlpcView *self,
     TpHandle buddy);
 
+void gabble_olpc_view_buddies_left_activity (GabbleOlpcView *self,
+    GArray *buddies, TpHandle room);
+
 G_END_DECLS
 
 #endif /* #ifndef __GABBLE_OLPC_VIEW_H__ */
diff --git a/tests/twisted/olpc/olpc-activity-search.py b/tests/twisted/olpc/olpc-activity-search.py
index 7b1797d..c7d0607 100644
--- a/tests/twisted/olpc/olpc-activity-search.py
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -382,6 +382,29 @@ def test(q, bus, conn, stream):
     assert contact == added[0]
     assert properties == {'color': '#CCCCCC,#DDDDDD'}
 
+    # Marcel left 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'
+    left = activity.addElement((None, 'left'))
+    left['jid'] = 'marcel 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)
+
+    # FIXME: BuddyInfo.ActivitiesChanged
+    view_event = q.expect_many(
+            EventPattern('dbus-signal', signal='BuddiesChanged'))
+
     # 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