[Telepathy-commits] [telepathy-gabble/master] Implement multi criterias buddy view requests

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Mon Oct 13 09:15:59 PDT 2008


---
 src/olpc-buddy-view.c                   |   60 +++++++++++--------------------
 tests/twisted/olpc/olpc-buddy-search.py |   37 +++++++++++++++++++
 2 files changed, 58 insertions(+), 39 deletions(-)

diff --git a/src/olpc-buddy-view.c b/src/olpc-buddy-view.c
index 0901c1b..60e0adc 100644
--- a/src/olpc-buddy-view.c
+++ b/src/olpc-buddy-view.c
@@ -264,59 +264,41 @@ gabble_olpc_buddy_view_send_request (GabbleOlpcView *view,
   GabbleOlpcBuddyView *self = GABBLE_OLPC_BUDDY_VIEW (view);
   GabbleOlpcBuddyViewPrivate *priv = GABBLE_OLPC_BUDDY_VIEW_GET_PRIVATE (self);
   LmMessage *query;
+  LmMessageNode *buddy_node;
   gchar *max_str, *id_str;
 
   max_str = g_strdup_printf ("%u", view->max_size);
   id_str = g_strdup_printf ("%u", view->id);
 
-  /* TODO: Implement multi criterias properties */
-  /* TODO: Always use the max_size argument */
+  query = lm_message_build_with_sub_type (view->conn->olpc_gadget_buddy,
+    LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
+    '(', "view", "",
+        '@', "xmlns", NS_OLPC_BUDDY,
+        '@', "id", id_str,
+        '@', "size", max_str,
+        '(', "buddy", "",
+          '*', &buddy_node,
+        ')',
+    ')', NULL);
+
+  /* BuddyView.Properties */
   if (g_hash_table_size (priv->properties) != 0)
     {
       LmMessageNode *properties_node;
 
-      query = lm_message_build_with_sub_type (view->conn->olpc_gadget_buddy,
-        LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
-        '(', "view", "",
-            '@', "xmlns", NS_OLPC_BUDDY,
-            '@', "id", id_str,
-            '@', "size", max_str,
-            '(', "buddy", "",
-              '(', "properties", "",
-                '*', &properties_node,
-                '@', "xmlns", NS_OLPC_BUDDY_PROPS,
-              ')',
-            ')',
-        ')',
-        NULL);
+      properties_node = lm_message_node_add_child (buddy_node, "properties",
+          NULL);
+      lm_message_node_set_attribute (properties_node, "xmlns",
+          NS_OLPC_BUDDY_PROPS);
 
       lm_message_node_add_children_from_properties (properties_node,
           priv->properties, "property");
     }
-  else if (priv->alias != NULL)
-    {
-      query = lm_message_build_with_sub_type (view->conn->olpc_gadget_buddy,
-        LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
-        '(', "view", "",
-            '@', "xmlns", NS_OLPC_BUDDY,
-            '@', "id", id_str,
-            '@', "size", max_str,
-            '(', "buddy", "",
-              '@', "alias", priv->alias,
-            ')',
-        ')',
-        NULL);
-    }
-  else
+
+  /* BuddyView.Alias */
+  if (priv->alias != NULL)
     {
-      query = lm_message_build_with_sub_type (view->conn->olpc_gadget_buddy,
-          LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
-          '(', "view", "",
-              '@', "xmlns", NS_OLPC_BUDDY,
-              '@', "id", id_str,
-              '@', "size", max_str,
-          ')',
-          NULL);
+      lm_message_node_set_attribute (buddy_node, "alias", priv->alias);
     }
 
   g_free (max_str);
diff --git a/tests/twisted/olpc/olpc-buddy-search.py b/tests/twisted/olpc/olpc-buddy-search.py
index 9207e90..c539553 100644
--- a/tests/twisted/olpc/olpc-buddy-search.py
+++ b/tests/twisted/olpc/olpc-buddy-search.py
@@ -398,5 +398,42 @@ def test(q, bus, conn, stream):
     event = q.expect('dbus-error', method='CreateChannel')
     assert event.error.get_dbus_name() == 'org.freedesktop.Telepathy.Errors.InvalidArgument'
 
+    # test alias and properties search
+    props = dbus.Dictionary({'color': '#AABBCC,#001122'}, signature='sv')
+    call_async(q, requests_iface, 'CreateChannel',
+        { tp_name_prefix + '.Channel.ChannelType':
+            olpc_name_prefix + '.Channel.Type.BuddyView',
+          olpc_name_prefix + '.Channel.Interface.View.MaxSize': 5,
+          olpc_name_prefix + '.Channel.Type.BuddyView.Properties': props,
+          olpc_name_prefix + '.Channel.Type.BuddyView.Alias': 'jean'
+          })
+
+    iq_event, return_event = q.expect_many(
+        EventPattern('stream-iq', to='gadget.localhost', query_ns=NS_OLPC_BUDDY),
+        EventPattern('dbus-return', method='CreateChannel'))
+
+    view = iq_event.stanza.firstChildElement()
+    assert view.name == 'view'
+    assert view['id'] == '4'
+    assert view['size'] == '5'
+
+    print iq_event.stanza.toXml()
+
+    properties_node = xpath.queryForNodes('/iq/view/buddy/properties',
+            iq_event.stanza)
+    props = parse_properties(properties_node[0])
+    assert props == {'color': ('str', '#AABBCC,#001122')}
+
+    buddy = xpath.queryForNodes('/iq/view/buddy', iq_event.stanza)
+    assert len(buddy) == 1
+    assert buddy[0]['alias'] == 'jean'
+
+    view_path = return_event.value[0]
+    props = return_event.value[1]
+    view4 = bus.get_object(conn.bus_name, view_path)
+
+    assert props['org.laptop.Telepathy.Channel.Type.BuddyView.Properties'] == dbus.Dictionary({'color': '#AABBCC,#001122'}, signature='sv')
+    assert props['org.laptop.Telepathy.Channel.Type.BuddyView.Alias'] == 'jean'
+
 if __name__ == '__main__':
     exec_test(test)
-- 
1.5.6.5




More information about the Telepathy-commits mailing list