[Telepathy-commits] [telepathy-gabble/master] Implement multi criterias activity view requests
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Mon Oct 13 09:27:48 PDT 2008
---
src/olpc-activity-view.c | 59 +++++++++-------------------
tests/twisted/olpc/olpc-activity-search.py | 40 +++++++++++++++++++
2 files changed, 59 insertions(+), 40 deletions(-)
diff --git a/src/olpc-activity-view.c b/src/olpc-activity-view.c
index 683c49e..6d29599 100644
--- a/src/olpc-activity-view.c
+++ b/src/olpc-activity-view.c
@@ -302,55 +302,45 @@ gabble_olpc_activity_view_send_request (GabbleOlpcView *view,
GabbleOlpcActivityViewPrivate *priv = \
GABBLE_OLPC_ACTIVITY_VIEW_GET_PRIVATE (self);
LmMessage *query;
+ LmMessageNode *activity_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_activity,
+ LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
+ '(', "view", "",
+ '@', "xmlns", NS_OLPC_ACTIVITY,
+ '@', "id", id_str,
+ '@', "size", max_str,
+ '(', "activity", "",
+ '*', &activity_node,
+ ')',
+ ')', NULL);
+
+ /* ActivityView.Properties */
if (g_hash_table_size (priv->properties) != 0)
{
LmMessageNode *properties_node;
- query = lm_message_build_with_sub_type (view->conn->olpc_gadget_activity,
- LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
- '(', "view", "",
- '@', "xmlns", NS_OLPC_ACTIVITY,
- '@', "id", id_str,
- '@', "size", max_str,
- '(', "activity", "",
- '(', "properties", "",
- '*', &properties_node,
- '@', "xmlns", NS_OLPC_ACTIVITY_PROPS,
- ')',
- ')',
- ')',
+ properties_node = lm_message_node_add_child (activity_node, "properties",
NULL);
+ lm_message_node_set_attribute (properties_node, "xmlns",
+ NS_OLPC_ACTIVITY_PROPS);
lm_message_node_add_children_from_properties (properties_node,
priv->properties, "property");
}
- else if (tp_handle_set_size (priv->participants) != 0)
+
+ /* ActivityView.Participants */
+ if (tp_handle_set_size (priv->participants) != 0)
{
- LmMessageNode *activity_node;
GArray *participants;
TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
TP_BASE_CONNECTION (view->conn), TP_HANDLE_TYPE_CONTACT);
guint i;
- query = lm_message_build_with_sub_type (view->conn->olpc_gadget_activity,
- LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
- '(', "view", "",
- '@', "xmlns", NS_OLPC_ACTIVITY,
- '@', "id", id_str,
- '@', "size", max_str,
- '(', "activity", "",
- '*', &activity_node,
- ')',
- ')',
- NULL);
-
/* For easier iteration */
participants = tp_handle_set_to_array (priv->participants);
@@ -368,17 +358,6 @@ gabble_olpc_activity_view_send_request (GabbleOlpcView *view,
g_array_free (participants, TRUE);
}
- else
- {
- query = lm_message_build_with_sub_type (view->conn->olpc_gadget_activity,
- LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
- '(', "view", "",
- '@', "xmlns", NS_OLPC_ACTIVITY,
- '@', "id", id_str,
- '@', "size", max_str,
- ')',
- NULL);
- }
g_free (max_str);
g_free (id_str);
diff --git a/tests/twisted/olpc/olpc-activity-search.py b/tests/twisted/olpc/olpc-activity-search.py
index c46cf0b..68c78ce 100644
--- a/tests/twisted/olpc/olpc-activity-search.py
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -522,6 +522,46 @@ 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 participants and properties search
+ props = dbus.Dictionary({'color': '#AABBCC,#001122'}, signature='sv')
+ participants = conn.RequestHandles(1, ["alice at localhost", "bob at localhost"])
+
+ call_async(q, requests_iface, 'CreateChannel',
+ { 'org.freedesktop.Telepathy.Channel.ChannelType':
+ 'org.laptop.Telepathy.Channel.Type.ActivityView',
+ 'org.laptop.Telepathy.Channel.Interface.View.MaxSize': 5,
+ 'org.laptop.Telepathy.Channel.Type.ActivityView.Properties': props,
+ 'org.laptop.Telepathy.Channel.Type.ActivityView.Participants': participants,
+ })
+
+
+ iq_event, return_event = q.expect_many(
+ EventPattern('stream-iq', to='gadget.localhost', query_ns=NS_OLPC_ACTIVITY),
+ EventPattern('dbus-return', method='CreateChannel'))
+
+ view = iq_event.stanza.firstChildElement()
+ assert view.name == 'view'
+ assert view['id'] == '4'
+ assert view['size'] == '5'
+
+ properties_nodes = xpath.queryForNodes('/iq/view/activity/properties',
+ iq_event.stanza)
+ props = parse_properties(properties_nodes[0])
+ assert props == {'color': ('str', '#AABBCC,#001122')}
+
+ buddies = xpath.queryForNodes('/iq/view/activity/buddy', iq_event.stanza)
+ assert len(buddies) == 2
+ assert (buddies[0]['jid'], buddies[1]['jid']) == ('alice at localhost',
+ 'bob at localhost')
+
+ 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.ActivityView.Properties'] == dbus.Dictionary({'color': '#AABBCC,#001122'}, signature='sv')
+ assert conn.InspectHandles(1, props['org.laptop.Telepathy.Channel.Type.ActivityView.Participants']) == \
+ ["alice at localhost", "bob at localhost"]
+
if __name__ == '__main__':
exec_test(test)
--
1.5.6.5
More information about the Telepathy-commits
mailing list