[Telepathy-commits] [telepathy-gabble/master] use active views to find buddies activities when PEP query failed
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Sep 26 10:02:22 PDT 2008
20080627105257-7fe3f-9aacafc3f67799061c4c7d529ec5600ddcd08ed1.gz
---
src/conn-olpc.c | 101 +++++++++++++++++++++++++++-
tests/twisted/olpc/olpc-activity-search.py | 28 ++++++--
2 files changed, 121 insertions(+), 8 deletions(-)
diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index 2822fb2..264b9bb 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -1012,6 +1012,97 @@ check_activity_properties (GabbleConnection *conn,
}
}
+struct find_activities_of_buddy_ctx
+{
+ TpHandle buddy;
+ GHashTable *activities;
+};
+
+static void
+find_activities_of_buddy (TpHandle contact,
+ GabbleOlpcView *view,
+ struct find_activities_of_buddy_ctx *ctx)
+{
+ GPtrArray *act;
+ guint i;
+
+ act = gabble_olpc_view_get_buddy_activities (view, ctx->buddy);
+
+ for (i = 0; i < act->len; i++)
+ {
+ GabbleOlpcActivity *activity;
+
+ activity = g_ptr_array_index (act, i);
+ g_hash_table_insert (ctx->activities, GUINT_TO_POINTER (activity->room),
+ activity);
+ }
+
+ g_ptr_array_free (act, TRUE);
+}
+
+static void
+copy_activity_to_array (TpHandle room,
+ GabbleOlpcActivity *activity,
+ GPtrArray *activities)
+{
+ GValue gvalue = { 0 };
+
+ if (activity->id == NULL)
+ {
+ DEBUG ("... activity #%u has no ID, skipping", room);
+ return;
+ }
+
+ g_value_init (&gvalue, GABBLE_STRUCT_TYPE_ACTIVITY);
+ g_value_take_boxed (&gvalue, dbus_g_type_specialized_construct
+ (GABBLE_STRUCT_TYPE_ACTIVITY));
+ dbus_g_type_struct_set (&gvalue,
+ 0, activity->id,
+ 1, activity->room,
+ G_MAXUINT);
+ DEBUG ("... activity #%u (ID %s)",
+ activity->room, activity->id);
+ g_ptr_array_add (activities, g_value_get_boxed (&gvalue));
+}
+
+static GPtrArray *
+find_buddy_activities_from_views (GabbleConnection *conn,
+ TpHandle contact)
+{
+ GPtrArray *result;
+ struct find_activities_of_buddy_ctx ctx;
+
+ result = g_ptr_array_new ();
+
+ /* We use a hash table first so we won't add twice the same activity */
+ ctx.activities = g_hash_table_new (g_direct_hash, g_direct_equal);
+ ctx.buddy = contact;
+
+ g_hash_table_foreach (conn->olpc_views, (GHFunc) find_activities_of_buddy,
+ &ctx);
+
+ /* Now compute the result array using the hash table */
+ g_hash_table_foreach (ctx.activities, (GHFunc) copy_activity_to_array,
+ result);
+
+ g_hash_table_destroy (ctx.activities);
+
+ return result;
+}
+
+static void
+return_buddy_activities_from_views (GabbleConnection *conn,
+ TpHandle contact,
+ DBusGMethodInvocation *context)
+{
+ GPtrArray *activities;
+
+ activities = find_buddy_activities_from_views (conn, contact);
+ gabble_svc_olpc_buddy_info_return_from_get_activities (context, activities);
+
+ free_activities (activities);
+}
+
static LmHandlerResult
get_activities_reply_cb (GabbleConnection *conn,
LmMessage *sent_msg,
@@ -1026,9 +1117,6 @@ get_activities_reply_cb (GabbleConnection *conn,
TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
(TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
- if (!check_query_reply_msg (reply_msg, context))
- return LM_HANDLER_RESULT_REMOVE_MESSAGE;
-
from = lm_message_node_get_attribute (reply_msg->node, "from");
if (from == NULL)
{
@@ -1049,6 +1137,13 @@ get_activities_reply_cb (GabbleConnection *conn,
return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
+ if (lm_message_get_sub_type (reply_msg) != LM_MESSAGE_SUB_TYPE_RESULT)
+ {
+ DEBUG ("Failed to query PEP node. Compute activities list using views");
+ return_buddy_activities_from_views (conn, from_handle, context);
+ return LM_HANDLER_RESULT_REMOVE_MESSAGE;
+ }
+
extract_activities (conn, reply_msg, from_handle);
activities = get_buddy_activities (conn, from_handle);
diff --git a/tests/twisted/olpc/olpc-activity-search.py b/tests/twisted/olpc/olpc-activity-search.py
index 5480d7d..1c602af 100644
--- a/tests/twisted/olpc/olpc-activity-search.py
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -21,8 +21,8 @@ NS_PUBSUB = "http://jabber.org/protocol/pubsub"
NS_DISCO_INFO = "http://jabber.org/protocol/disco#info"
NS_DISCO_ITEMS = "http://jabber.org/protocol/disco#items"
-
NS_AMP = "http://jabber.org/protocol/amp"
+NS_STANZA = "urn:ietf:params:xml:ns:xmpp-stanzas"
def test(q, bus, conn, stream):
conn.Connect()
@@ -134,10 +134,28 @@ def test(q, bus, conn, stream):
assert props == {'color': '#AABBCC,#CCBBAA'}
# and their activities
- # FIXME
- #activities = buddy_prop_iface.GetActivities(members_handles[0])
- #assert len(activities) == 1
- #assert activities[0] == 'activity1', room1_handle
+ call_async (q, buddy_prop_iface, 'GetActivities', members_handles[0])
+
+ event = q.expect('stream-iq', to='lucien at localhost', query_name='pubsub',
+ query_ns=NS_PUBSUB)
+ iq = event.stanza
+ # return an error, we can't query pubsub node
+ reply = IQ(stream, "error")
+ reply['id'] = iq['id']
+ reply['from'] = iq['to']
+ pubsub = reply.addElement((NS_PUBSUB, 'pubsub'))
+ items = pubsub.addElement((None, 'items'))
+ items['node'] = 'http://laptop.org/xmpp/activities'
+ error = reply.addElement((None, 'error'))
+ error['type'] = 'auth'
+ error.addElement((NS_STANZA, 'not-authorized'))
+ error.addElement(("%s#errors" % NS_PUBSUB, 'presence-subscription-required'))
+ stream.send(reply)
+
+ event = q.expect('dbus-return', method='GetActivities')
+ activities = event.value[0]
+ assert len(activities) == 1
+ assert activities[0] == ('activity1', room1_handle)
# activity search by properties (view 1)
props = {'color': '#AABBCC,#001122'}
--
1.5.6.5
More information about the Telepathy-commits
mailing list