[telepathy-gabble/master] emit a presence update for subscribed contacts when we get the roster
Dafydd Harries
dafydd.harries at collabora.co.uk
Thu Sep 17 12:30:17 PDT 2009
A GetPresence call for a contact we're subscribed to before we get the roster
will return unknown; a call after we get the roster will return offline. This
commit advertises that change to clients.
---
src/roster.c | 12 +++++
tests/twisted/Makefile.am | 1 +
tests/twisted/presence/initial-contact-presence.py | 46 ++++++++++++++++++++
3 files changed, 59 insertions(+), 0 deletions(-)
create mode 100644 tests/twisted/presence/initial-contact-presence.py
diff --git a/src/roster.c b/src/roster.c
index 87c4eaf..660df92 100644
--- a/src/roster.c
+++ b/src/roster.c
@@ -35,6 +35,7 @@
#include "caps-channel-manager.h"
#include "conn-aliasing.h"
+#include "conn-presence.h"
#include "connection.h"
#include "debug.h"
#include "namespaces.h"
@@ -1543,6 +1544,17 @@ got_roster_iq (GabbleRoster *roster,
_gabble_roster_item_remove (roster,
g_array_index (removed, TpHandle, i));
+ if (sub_type == LM_MESSAGE_SUB_TYPE_RESULT)
+ {
+ GArray *members;
+
+ tp_group_mixin_get_members ((GObject *) pub_chan, &members, NULL);
+ /* If somebody's on our roster, and we haven't received presence
+ * from them, we know they're offline. Let clients know that.
+ */
+ conn_presence_emit_presence_update (priv->conn, members);
+ }
+
tp_intset_destroy (pub_add);
tp_intset_destroy (pub_rem);
tp_intset_destroy (sub_add);
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index eb8c24e..4920c2a 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -33,6 +33,7 @@ TWISTED_TESTS = \
olpc/gadget-publish.py \
olpc/gadget-restarted.py \
olpc/view-presence.py \
+ presence/initial-contact-presence.py \
presence/initial-presence.py \
presence/presence.py \
roster/ensure.py \
diff --git a/tests/twisted/presence/initial-contact-presence.py b/tests/twisted/presence/initial-contact-presence.py
new file mode 100644
index 0000000..eff7552
--- /dev/null
+++ b/tests/twisted/presence/initial-contact-presence.py
@@ -0,0 +1,46 @@
+"""
+Test that contacts we're subscribed to have their presence go from unknown to
+offline when we get the roster.
+"""
+
+from gabbletest import exec_test
+from servicetest import assertEquals
+
+import constants as cs
+import ns
+
+from twisted.words.xish import domish
+
+def make_roster_item(jid, subscription):
+ item = domish.Element((None, 'item'))
+ item['jid'] = jid
+ item['subscription'] = subscription
+ return item
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+ event = q.expect('stream-iq', query_ns=ns.ROSTER)
+
+ amy, bob, che = conn.RequestHandles(cs.HT_CONTACT,
+ ['amy at foo.com', 'bob at foo.com', 'che at foo.com'])
+ assertEquals({amy: (cs.PRESENCE_UNKNOWN, u'unknown', u''),
+ bob: (cs.PRESENCE_UNKNOWN, u'unknown', u''),
+ che: (cs.PRESENCE_UNKNOWN, u'unknown', u'')},
+ conn.SimplePresence.GetPresences([amy, bob, che]))
+
+ event.stanza['type'] = 'result'
+ event.query.addChild(make_roster_item('amy at foo.com', 'both'))
+ event.query.addChild(make_roster_item('bob at foo.com', 'from'))
+ event.query.addChild(make_roster_item('che at foo.com', 'to'))
+ stream.send(event.stanza)
+
+ q.expect('dbus-signal', signal='PresencesChanged',
+ args=[{amy: (cs.PRESENCE_OFFLINE, u'offline', u''),
+ bob: (cs.PRESENCE_OFFLINE, u'offline', u'')}])
+ assertEquals({amy: (cs.PRESENCE_OFFLINE, u'offline', u''),
+ bob: (cs.PRESENCE_OFFLINE, u'offline', u''),
+ che: (cs.PRESENCE_UNKNOWN, u'unknown', u'')},
+ conn.SimplePresence.GetPresences([amy, bob, che]))
+
+if __name__ == '__main__':
+ exec_test(test)
--
1.5.6.5
More information about the telepathy-commits
mailing list