[Telepathy-commits] [telepathy-gabble/master] implement SearchBuddiesByAlias

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


20080724125051-7fe3f-b82535e53fa57f35576080fb0712437e5a7efc15.gz
---
 src/conn-olpc.c                         |   67 +++++++++++++++++++++++++++++++
 tests/twisted/olpc/olpc-buddy-search.py |   46 +++++++++++++++++++++
 2 files changed, 113 insertions(+), 0 deletions(-)

diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index f2caba1..45900ca 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -3889,6 +3889,72 @@ olpc_gadget_search_buddies_by_properties (GabbleSvcOLPCGadget *iface,
   lm_message_unref (query);
 }
 
+static void
+olpc_gadget_search_buddies_by_alias (GabbleSvcOLPCGadget *iface,
+                                     const gchar *alias,
+                                     DBusGMethodInvocation *context)
+{
+  GabbleConnection *conn = GABBLE_CONNECTION (iface);
+  LmMessage *query;
+  gchar *id_str;
+  gchar *object_path;
+  guint id;
+  GabbleOlpcView *view;
+
+  if (!check_gadget_buddy (conn, context))
+    return;
+
+  view = create_view (conn, GABBLE_OLPC_VIEW_TYPE_BUDDY);
+  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_buddy,
+      LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
+      '(', "view", "",
+          '@', "xmlns", NS_OLPC_BUDDY,
+          '@', "id", id_str,
+          '(', "buddy", "",
+            '@', "alias", alias,
+          ')',
+      ')',
+      NULL);
+
+  g_free (id_str);
+
+  if (!_gabble_connection_send_with_reply (conn, query,
+        buddy_query_result_cb, G_OBJECT (view), NULL, NULL))
+    {
+      GError error = { TP_ERRORS, TP_ERROR_NETWORK_ERROR,
+        "Failed to send buddy 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_gadget_return_from_search_buddies_by_alias (context,
+      object_path);
+
+  g_free (object_path);
+  lm_message_unref (query);
+}
+
 static LmHandlerResult
 activity_query_result_cb (GabbleConnection *conn,
                           LmMessage *sent_msg,
@@ -4213,6 +4279,7 @@ olpc_gadget_iface_init (gpointer g_iface,
     klass, olpc_gadget_##x)
   IMPLEMENT(request_random_buddies);
   IMPLEMENT(search_buddies_by_properties);
+  IMPLEMENT(search_buddies_by_alias);
   IMPLEMENT(request_random_activities);
   IMPLEMENT(search_activities_by_properties);
   IMPLEMENT(search_activities_by_participants);
diff --git a/tests/twisted/olpc/olpc-buddy-search.py b/tests/twisted/olpc/olpc-buddy-search.py
index cdd0879..0f1990e 100644
--- a/tests/twisted/olpc/olpc-buddy-search.py
+++ b/tests/twisted/olpc/olpc-buddy-search.py
@@ -282,6 +282,43 @@ def test(q, bus, conn, stream):
 
     # FIXME: test current-activity change from gadget
 
+    # test alias search
+    call_async(q, gadget_iface, 'SearchBuddiesByAlias', "tom")
+
+    iq_event, return_event = q.expect_many(
+        EventPattern('stream-iq', to='gadget.localhost',
+            query_ns=NS_OLPC_BUDDY),
+        EventPattern('dbus-return', method='SearchBuddiesByAlias'))
+
+    view = iq_event.stanza.firstChildElement()
+    assert view.name == 'view'
+    assert view['id'] == '2'
+    buddy = xpath.queryForNodes('/iq/view/buddy', iq_event.stanza)
+    assert len(buddy) == 1
+    assert buddy[0]['alias'] == 'tom'
+
+    # reply to random query
+    reply = make_result_iq(stream, iq_event.stanza)
+    reply['from'] = 'gadget.localhost'
+    reply['to'] = 'alice at localhost'
+    view = xpath.queryForNodes('/iq/view', reply)[0]
+    buddy = view.addElement((None, "buddy"))
+    buddy['jid'] = 'tom at localhost'
+    buddy = view.addElement((None, "buddy"))
+    buddy['jid'] = 'thomas at localhost'
+    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.View')
+
+    event = q.expect('dbus-signal', signal='BuddiesChanged')
+    added, removed = event.args
+    assert removed == []
+    assert len(added) == 2
+    assert sorted(conn.InspectHandles(1, added)) == ['thomas at localhost',
+            'tom at localhost']
+
     # close view 0
     call_async(q, view0_iface, 'Close')
     event, _ = q.expect_many(
@@ -300,5 +337,14 @@ 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