[Telepathy-commits] [telepathy-gabble/master] remove activity from existing views
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Sep 26 10:02:22 PDT 2008
20080612121732-7fe3f-2bac629d1a74703830b0262a50bd714b1de390c2.gz
---
src/conn-olpc.c | 70 +++++++++++++++++++++++++++-
src/olpc-view.c | 38 +++++++++++++++
src/olpc-view.h | 3 +
tests/twisted/olpc/olpc-activity-search.py | 39 ++++++++++++++-
4 files changed, 146 insertions(+), 4 deletions(-)
diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index a1715ed..ea491f7 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -3242,13 +3242,76 @@ buddy_removed (GabbleConnection *conn,
view = g_hash_table_lookup (conn->olpc_views, GUINT_TO_POINTER (id));
if (view == NULL)
{
- DEBUG ("no buddy view with ID %u", id);
+ DEBUG ("no view with ID %u", id);
return;
}
remove_buddies_from_view_from_node (conn, view, removed);
}
+static gboolean
+remove_activities_from_view_from_node (GabbleConnection *conn,
+ GabbleOlpcView *view,
+ LmMessageNode *node)
+{
+ TpHandleSet *rooms;
+ TpHandleRepoIface *room_repo = tp_base_connection_get_handles (
+ (TpBaseConnection*) conn, TP_HANDLE_TYPE_ROOM);
+ LmMessageNode *activity;
+
+ rooms = tp_handle_set_new (room_repo);
+
+ for (activity = node->children; activity != NULL; activity = activity->next)
+ {
+ const gchar *room;
+ TpHandle handle;
+
+ if (tp_strdiff (activity->name, "activity"))
+ continue;
+
+ room = lm_message_node_get_attribute (activity, "room");
+
+ handle = tp_handle_ensure (room_repo, room, NULL, NULL);
+ if (handle == 0)
+ {
+ DEBUG ("Invalid room: %s", room);
+ tp_handle_set_destroy (rooms);
+ return FALSE;
+ }
+
+ tp_handle_set_add (rooms, handle);
+ tp_handle_unref (room_repo, handle);
+ }
+
+ gabble_olpc_view_remove_activities (view, rooms);
+ tp_handle_set_destroy (rooms);
+
+ return TRUE;
+}
+
+static void
+activity_removed (GabbleConnection *conn,
+ LmMessageNode *removed)
+{
+ const gchar *id_str;
+ guint id;
+ GabbleOlpcView *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_views, GUINT_TO_POINTER (id));
+ if (view == NULL)
+ {
+ DEBUG ("no view with ID %u", id);
+ return;
+ }
+
+ remove_activities_from_view_from_node (conn, view, removed);
+}
+
LmHandlerResult
conn_olpc_msg_cb (LmMessageHandler *handler,
LmConnection *connection,
@@ -3309,6 +3372,11 @@ conn_olpc_msg_cb (LmMessageHandler *handler,
{
activity_added (conn, node);
}
+ else if (!tp_strdiff (node->name, "removed") &&
+ !tp_strdiff (ns, NS_OLPC_ACTIVITY))
+ {
+ activity_removed (conn, node);
+ }
}
return LM_HANDLER_RESULT_REMOVE_MESSAGE;
diff --git a/src/olpc-view.c b/src/olpc-view.c
index 3930754..db37da6 100644
--- a/src/olpc-view.c
+++ b/src/olpc-view.c
@@ -545,6 +545,44 @@ gabble_olpc_view_add_activities (GabbleOlpcView *self,
g_ptr_array_free (empty, TRUE);
}
+void
+gabble_olpc_view_remove_activities (GabbleOlpcView *self,
+ TpHandleSet *rooms)
+{
+ GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+ GPtrArray *removed, *empty;
+ GArray *array;
+ guint i;
+
+ /* for easier iteration */
+ array = tp_handle_set_to_array (rooms);
+
+ removed = g_ptr_array_new ();
+ empty = g_ptr_array_new ();
+
+ for (i = 0; i < array->len; i++)
+ {
+ TpHandle handle;
+ GabbleOlpcActivity *activity;
+
+ handle = g_array_index (array, TpHandle, i);
+
+ activity = g_hash_table_lookup (priv->activities,
+ GUINT_TO_POINTER (handle));
+ if (activity == NULL)
+ continue;
+
+ add_activity_to_array (handle, activity, removed);
+ g_hash_table_remove (priv->activities, GUINT_TO_POINTER (handle));
+ }
+
+ gabble_svc_olpc_view_emit_activities_changed (self, empty, removed);
+
+ free_activities_array (removed);
+ g_ptr_array_free (empty, TRUE);
+ g_array_free (array, TRUE);
+}
+
static void
view_iface_init (gpointer g_iface,
gpointer iface_data)
diff --git a/src/olpc-view.h b/src/olpc-view.h
index c1608bd..6a218e2 100644
--- a/src/olpc-view.h
+++ b/src/olpc-view.h
@@ -85,6 +85,9 @@ GHashTable * gabble_olpc_view_get_buddy_properties (GabbleOlpcView *self,
void gabble_olpc_view_add_activities (GabbleOlpcView *self,
GHashTable *activities);
+void gabble_olpc_view_remove_activities (GabbleOlpcView *self,
+ TpHandleSet *rooms);
+
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 02e4ce2..3829a28 100644
--- a/tests/twisted/olpc/olpc-activity-search.py
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -117,9 +117,9 @@ def test(q, bus, conn, stream):
event = q.expect('dbus-signal', signal='ActivitiesChanged')
added, removed = event.args
assert len(added) == 1
- id, handle = added[0]
+ id, room1_handle = added[0]
assert id == 'activity1'
- assert sorted(conn.InspectHandles(2, [handle])) == \
+ assert sorted(conn.InspectHandles(2, [room1_handle])) == \
['room1 at conference.localhost']
act = view0_iface.GetActivities()
@@ -271,11 +271,12 @@ def test(q, bus, conn, stream):
rule['action'] ='error'
stream.send(message)
- # participants are added to view
+ # participants are added to view
event = q.expect('dbus-signal', signal='BuddiesChanged')
members_handles, removed = event.args
assert conn.InspectHandles(1, members_handles) == ['fernand at localhost']
+ # activity is added too
event = q.expect('dbus-signal', signal='ActivitiesChanged')
added, removed = event.args
assert len(added) == 1
@@ -284,6 +285,38 @@ def test(q, bus, conn, stream):
assert sorted(conn.InspectHandles(2, [handle])) == \
['room4 at conference.localhost']
+ # remove one activity from view 0
+ message = domish.Element((None, 'message'))
+ message['from'] = 'gadget.localhost'
+ message['to'] = 'alice at localhost'
+ message['type'] = 'notice'
+ removed = message.addElement((NS_OLPC_ACTIVITY, 'removed'))
+ removed['id'] = '0'
+ activity = removed.addElement((None, 'activity'))
+ activity['id'] = 'activity1'
+ activity['room'] = 'room1 at conference.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)
+
+ # participants are removed from the view
+ # FIXME
+ #event = q.expect('dbus-signal', signal='BuddiesChanged')
+ #members_handles, removed = event.args
+ #assert conn.InspectHandles(1, members_handles) == ['fernand at localhost']
+
+ # activity is removed
+ event = q.expect('dbus-signal', signal='ActivitiesChanged')
+ added, removed = event.args
+ assert added == []
+ assert len(removed) == 1
+ id, handle = removed[0]
+ assert id == 'activity1'
+ assert handle == room1_handle
+
# 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