[Telepathy-commits] [telepathy-gabble/master] update properties stored in view according change messages
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Sep 26 10:02:23 PDT 2008
20080627133613-7fe3f-03ef550868268d8d5c6717d32941e79e721f0967.gz
---
src/conn-olpc.c | 29 ++++++++++++++++++++++-
tests/twisted/olpc/olpc-buddy-search.py | 37 +++++++++++++++++++++++++++++-
2 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index 264b9bb..0841db2 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -565,6 +565,8 @@ olpc_buddy_info_get_properties (GabbleSvcOLPCBuddyInfo *iface,
return;
/* First check if we can find properties in a buddy view */
+ /* FIXME: Maybe we should first try the PEP node as we do for buddy
+ * activities ? */
properties = find_buddy_properties_from_views (conn, contact);
if (properties != NULL)
{
@@ -2953,10 +2955,12 @@ buddy_changed (GabbleConnection *conn,
LmMessageNode *change)
{
LmMessageNode *node;
- const gchar *jid;
+ const gchar *jid, *id_str;
+ guint id;
TpHandle handle;
TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
(TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
+ GabbleOlpcView *view;
jid = lm_message_node_get_attribute (change, "jid");
if (jid == NULL)
@@ -2965,6 +2969,21 @@ buddy_changed (GabbleConnection *conn,
return;
}
+ id_str = lm_message_node_get_attribute (change, "id");
+ if (id_str == NULL)
+ {
+ DEBUG ("No view ID attribute in change message. Discard");
+ return;
+ }
+
+ id = strtoul (id_str, NULL, 10);
+ view = g_hash_table_lookup (conn->olpc_views, GUINT_TO_POINTER (id));
+ if (view == NULL)
+ {
+ DEBUG ("No active view with ID %u", id);
+ return;
+ }
+
/* FIXME: Should we really have to ensure the handle? If we receive changes
* notifications that means this contact is in your search frame so maybe
* we should keep a ref on his handle */
@@ -2984,10 +3003,16 @@ buddy_changed (GabbleConnection *conn,
properties = lm_message_node_extract_properties (node,
"property");
+
+ if (view != NULL)
+ {
+ gabble_olpc_view_set_buddy_properties (view, handle, properties);
+ }
+
gabble_svc_olpc_buddy_info_emit_properties_changed (conn, handle,
properties);
- g_hash_table_destroy (properties);
+ g_hash_table_unref (properties);
}
node = lm_message_node_get_child_with_namespace (change,
diff --git a/tests/twisted/olpc/olpc-buddy-search.py b/tests/twisted/olpc/olpc-buddy-search.py
index 00d9b75..c6ccd0d 100644
--- a/tests/twisted/olpc/olpc-buddy-search.py
+++ b/tests/twisted/olpc/olpc-buddy-search.py
@@ -153,11 +153,42 @@ def test(q, bus, conn, stream):
assert sorted(conn.InspectHandles(1, added)) == ['bob at localhost',
'charles at localhost']
+ event = q.expect('dbus-signal', signal='PropertiesChanged')
+ event = q.expect('dbus-signal', signal='PropertiesChanged')
+
# we can now get bob's properties
- handle = conn.RequestHandles(1, ['bob at localhost'])[0]
- props = buddy_info_iface.GetProperties(handle)
+ bob_handle = conn.RequestHandles(1, ['bob at localhost'])[0]
+ props = buddy_info_iface.GetProperties(bob_handle)
assert props == {'color': '#005FE4,#00A0FF'}
+ # Bob changed his properties
+ message = domish.Element(('jabber:client', 'message'))
+ message['from'] = 'gadget.localhost'
+ message['to'] = 'test at localhost'
+ message['type'] = 'notice'
+
+ change = message.addElement((NS_OLPC_BUDDY, 'change'))
+ change['jid'] = 'bob at localhost'
+ change['id'] = '0'
+ properties = change.addElement((NS_OLPC_BUDDY_PROPS, 'properties'))
+ property = properties.addElement((None, 'property'))
+ property['type'] = 'str'
+ property['name'] = 'color'
+ property.addContent('#FFFFFF,#AAAAAA')
+ amp = message.addElement((NS_AMP, 'amp'))
+ rule = amp.addElement((None, 'rule'))
+ rule['condition'] = 'deliver-at'
+ rule['value'] = 'stored'
+ rule['action'] ='error'
+ stream.send(message)
+
+ event = q.expect('dbus-signal', signal='PropertiesChanged',
+ args=[bob_handle, {'color': '#FFFFFF,#AAAAAA'}])
+
+ # we now get the new properties
+ props = buddy_info_iface.GetProperties(bob_handle)
+ assert props == {'color': '#FFFFFF,#AAAAAA'}
+
# buddy search
props = {'color': '#AABBCC,#001122'}
call_async(q, gadget_iface, 'SearchBuddiesByProperties', props)
@@ -267,6 +298,8 @@ def test(q, bus, conn, stream):
members = sorted(conn.InspectHandles(1, members))
assert sorted(members) == ['charles at localhost', 'oscar at localhost']
+ # FIXME: test current-activity change from gadget
+
# close view 0
call_async(q, view0_iface, 'Close')
event, _ = q.expect_many(
--
1.5.6.5
More information about the Telepathy-commits
mailing list