[Telepathy-commits] [telepathy-gabble/master] implement org.laptop.Telepathy.Activity.SearchByParticipants()

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


20080521143400-7fe3f-f4fc29f09daf3d2813b98ade5f3df7910be36489.gz
---
 src/conn-olpc.c                            |   83 ++++++++++++++++++++++++++++
 tests/twisted/olpc/olpc-activity-search.py |   47 ++++++++++++++++
 2 files changed, 130 insertions(+), 0 deletions(-)

diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index bc15944..3d78c1c 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -3488,6 +3488,88 @@ olpc_activity_search_by_properties (GabbleSvcOLPCActivity *iface,
   lm_message_unref (query);
 }
 
+static void
+olpc_activity_search_by_participants (GabbleSvcOLPCActivity *iface,
+                                      const GArray *participants,
+                                      DBusGMethodInvocation *context)
+{
+  GabbleConnection *conn = GABBLE_CONNECTION (iface);
+  LmMessage *query;
+  LmMessageNode *activity_node;
+  gchar *id_str;
+  gchar *object_path;
+  guint id, i;
+  GabbleOlpcActivityView *view;
+  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
+      (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
+
+  if (!check_gadget_activity (conn, context))
+    return;
+
+  view = create_activity_view (conn);
+  if (view == NULL)
+    {
+      GError error = { TP_ERRORS, TP_ERROR_NETWORK_ERROR,
+        "can't create view" };
+
+      DEBUG ("%s", error.message);
+      dbus_g_method_return_error (context, &error);
+      return;
+    }
+
+  g_object_get (view,
+      "id", &id,
+      "object-path", &object_path,
+      NULL);
+
+  id_str = g_strdup_printf ("%u", id);
+
+  query = lm_message_build_with_sub_type (conn->olpc_gadget_activity,
+      LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
+      '(', "query", "",
+          '@', "xmlns", NS_OLPC_ACTIVITY,
+          '@', "id", id_str,
+          '(', "activity", "",
+            '*', &activity_node,
+          ')',
+      ')',
+      NULL);
+
+  g_free (id_str);
+
+  for (i = 0; i < participants->len; i++)
+    {
+      LmMessageNode *buddy;
+      const gchar *jid;
+
+      jid = tp_handle_inspect (contact_repo,
+          g_array_index (participants, TpHandle, i));
+      g_print ("aaaaaaa %s\n", jid);
+
+      buddy = lm_message_node_add_child (activity_node, "buddy", "");
+      lm_message_node_set_attribute (buddy, "jid", jid);
+    }
+
+  if (!_gabble_connection_send_with_reply (conn, query,
+        activity_query_result_cb, G_OBJECT (view), NULL, NULL))
+    {
+      GError error = { TP_ERRORS, TP_ERROR_NETWORK_ERROR,
+        "Failed to send activity search query to server" };
+
+      DEBUG ("%s", error.message);
+      dbus_g_method_return_error (context, &error);
+      lm_message_unref (query);
+      g_free (object_path);
+      return;
+    }
+
+  gabble_svc_olpc_activity_return_from_search_by_participants (context,
+      object_path);
+
+  g_free (object_path);
+  lm_message_unref (query);
+}
+
 void
 olpc_activity_iface_init (gpointer g_iface,
                           gpointer iface_data)
@@ -3498,5 +3580,6 @@ olpc_activity_iface_init (gpointer g_iface,
     klass, olpc_activity_##x)
   IMPLEMENT(request_random);
   IMPLEMENT(search_by_properties);
+  IMPLEMENT(search_by_participants);
 #undef IMPLEMENT
 }
diff --git a/tests/twisted/olpc/olpc-activity-search.py b/tests/twisted/olpc/olpc-activity-search.py
index 3d97d0c..980a0cd 100644
--- a/tests/twisted/olpc/olpc-activity-search.py
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -148,6 +148,44 @@ def test(q, bus, conn, stream):
     assert conn.InspectHandles(2, [handle])[0] == 'room2 at conference.localhost'
     assert props == {'color': '#AABBCC,#001122'}
 
+    # activity search by participants
+    participants = conn.RequestHandles(1, ["alice at localhost", "bob at localhost"])
+    call_async(q, activity_iface, 'SearchByParticipants', participants)
+
+    iq_event, return_event = q.expect_many(
+        EventPattern('stream-iq', to='gadget.localhost', query_ns=NS_OLPC_ACTIVITY),
+        EventPattern('dbus-return', method='SearchByParticipants'))
+
+    buddies = xpath.queryForNodes('/iq/query/activity/buddy', iq_event.stanza)
+    query = iq_event.stanza.firstChildElement()
+    assert query.name == 'query'
+    assert query['id'] == '2'
+    assert len(buddies) == 2
+    assert (buddies[0]['jid'], buddies[1]['jid']) == ('alice at localhost', 'bob at localhost')
+
+    # reply to request
+    reply = make_result_iq(stream, iq_event.stanza)
+    reply['from'] = 'gadget.localhost'
+    reply['to'] = 'alice at localhost'
+    query = xpath.queryForNodes('/iq/query', reply)[0]
+    activity = query.addElement((None, "activity"))
+    activity['room'] = 'room2 at conference.localhost'
+    properties = activity.addElement((NS_OLPC_ACTIVITY_PROPS, "properties"))
+    property = properties.addElement((None, "property"))
+    property['type'] = 'str'
+    property['name'] = 'color'
+    property.addContent('#AABBCC,#001122')
+    stream.send(reply)
+
+    view_path = return_event.value[0]
+    view2 = bus.get_object(conn.bus_name, view_path)
+    view2_iface = dbus.Interface(view2, 'org.laptop.Telepathy.ActivityView')
+
+    event = q.expect('dbus-signal', signal='ActivityPropertiesChanged')
+    handle, props = event.args
+    assert conn.InspectHandles(2, [handle])[0] == 'room2 at conference.localhost'
+    assert props == {'color': '#AABBCC,#001122'}
+
     # close view 0
     call_async(q, view0_iface, 'Close')
     event, _ = q.expect_many(
@@ -166,6 +204,15 @@ def test(q, bus, conn, stream):
     assert len(close) == 1
     assert close[0]['id'] == '1'
 
+    # close view 2
+    call_async(q, view2_iface, 'Close')
+    event, _ = q.expect_many(
+        EventPattern('stream-message', to='gadget.localhost'),
+        EventPattern('dbus-return', method='Close'))
+    close = xpath.queryForNodes('/message/close', event.stanza)
+    assert len(close) == 1
+    assert close[0]['id'] == '2'
+
 
 if __name__ == '__main__':
     exec_test(test)
-- 
1.5.6.5




More information about the Telepathy-commits mailing list