[Telepathy-commits] [telepathy-gabble/master] invite gadget when an activity becomes public
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Sep 26 10:02:18 PDT 2008
20080529115830-7fe3f-eef4147b23e6112d217c5350485c1828482acfe5.gz
---
src/conn-olpc.c | 18 +++++
tests/twisted/olpc/gadget-invite.py | 142 +++++++++++++++++++++++++++++++++++
2 files changed, 160 insertions(+), 0 deletions(-)
create mode 100644 tests/twisted/olpc/gadget-invite.py
diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index f2211c4..62338c1 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -1781,6 +1781,18 @@ refresh_invitations (GabbleMucChannel *chan,
return TRUE;
}
+static gboolean
+invite_gadget (GabbleConnection *conn,
+ GabbleMucChannel *muc)
+{
+ if (!check_gadget_activity (conn, NULL))
+ return FALSE;
+
+ DEBUG ("Activity becomes public. Invite gadget to it");
+ return gabble_muc_channel_send_invite (muc, conn->olpc_gadget_activity,
+ "Share activity", NULL);
+}
+
static void
olpc_activity_properties_set_properties (GabbleSvcOLPCActivityProperties *iface,
guint room,
@@ -1875,6 +1887,12 @@ olpc_activity_properties_set_properties (GabbleSvcOLPCActivityProperties *iface,
ctx->visibility_changed = (was_visible != is_visible);
ctx->info = info;
+ if (!was_visible && is_visible)
+ {
+ /* activity becomes visible. Invite gadget */
+ invite_gadget (conn, muc_channel);
+ }
+
if (was_visible || is_visible)
{
if (!upload_activity_properties_pep (conn,
diff --git a/tests/twisted/olpc/gadget-invite.py b/tests/twisted/olpc/gadget-invite.py
new file mode 100644
index 0000000..15547f0
--- /dev/null
+++ b/tests/twisted/olpc/gadget-invite.py
@@ -0,0 +1,142 @@
+"""
+test gadget invitation when an activity becomes public
+"""
+
+import dbus
+
+from servicetest import call_async, EventPattern
+from gabbletest import exec_test, make_result_iq, acknowledge_iq, sync_stream
+
+from twisted.words.xish import domish, xpath
+from twisted.words.protocols.jabber.client import IQ
+
+NS_OLPC_BUDDY_PROPS = "http://laptop.org/xmpp/buddy-properties"
+NS_OLPC_ACTIVITIES = "http://laptop.org/xmpp/activities"
+NS_OLPC_CURRENT_ACTIVITY = "http://laptop.org/xmpp/current-activity"
+NS_OLPC_ACTIVITY_PROPS = "http://laptop.org/xmpp/activity-properties"
+NS_OLPC_BUDDY = "http://laptop.org/xmpp/buddy"
+NS_OLPC_ACTIVITY = "http://laptop.org/xmpp/activity"
+
+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"
+
+def join_channel(name, q, conn, stream):
+ call_async(q, conn, 'RequestHandles', 2, [name])
+
+ # announce conference service
+ event = q.expect('stream-iq', to='conference.localhost', query_ns=NS_DISCO_INFO)
+ reply = make_result_iq(stream, event.stanza)
+ feature = reply.firstChildElement().addElement('feature')
+ feature['var'] = 'http://jabber.org/protocol/muc'
+ stream.send(reply)
+
+ event = q.expect('dbus-return', method='RequestHandles')
+ handles = event.value[0]
+
+ call_async(q, conn, 'RequestChannel',
+ 'org.freedesktop.Telepathy.Channel.Type.Text', 2, handles[0], True)
+
+ event = q.expect('stream-presence', to='myroom at conference.localhost/test')
+ # Send presence for own membership of room.
+ presence = domish.Element((None, 'presence'))
+ presence['from'] = 'myroom at conference.localhost/test'
+ x = presence.addElement(('http://jabber.org/protocol/muc#user', 'x'))
+ item = x.addElement('item')
+ item['affiliation'] = 'none'
+ item['role'] = 'participant'
+ stream.send(presence)
+
+ event = q.expect('dbus-return', method='RequestChannel')
+ return handles[0], event.value[0]
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+
+ _, iq_event, disco_event = q.expect_many(
+ EventPattern('dbus-signal', signal='StatusChanged', args=[0, 1]),
+ EventPattern('stream-iq', to=None, query_ns='vcard-temp',
+ query_name='vCard'),
+ EventPattern('stream-iq', to='localhost', query_ns=NS_DISCO_ITEMS))
+
+ acknowledge_iq(stream, iq_event.stanza)
+
+ act_prop_iface = dbus.Interface(conn, 'org.laptop.Telepathy.ActivityProperties')
+ buddy_info_iface = dbus.Interface(conn, 'org.laptop.Telepathy.BuddyInfo')
+
+ # announce Gadget service
+ reply = make_result_iq(stream, disco_event.stanza)
+ query = xpath.queryForNodes('/iq/query', reply)[0]
+ item = query.addElement((None, 'item'))
+ item['jid'] = 'gadget.localhost'
+ stream.send(reply)
+
+ # wait for Gadget disco#info query
+ event = q.expect('stream-iq', to='gadget.localhost', query_ns=NS_DISCO_INFO)
+ reply = make_result_iq(stream, event.stanza)
+ query = xpath.queryForNodes('/iq/query', reply)[0]
+ identity = query.addElement((None, 'identity'))
+ identity['category'] = 'collaboration'
+ identity['type'] = 'gadget'
+ identity['name'] = 'OLPC Gadget'
+ feature = query.addElement((None, 'feature'))
+ feature['var'] = NS_OLPC_BUDDY
+ feature = query.addElement((None, 'feature'))
+ feature['var'] = NS_OLPC_ACTIVITY
+ stream.send(reply)
+
+ q.expect_many(EventPattern('dbus-signal', signal='BuddyGadgetDiscovered'),
+ EventPattern('dbus-signal', signal='ActivityGadgetDiscovered'))
+
+ # join a room
+ room_handle, room_path = join_channel('myroom at conference.localhost',
+ q, conn, stream)
+
+ call_async (q, buddy_info_iface, 'SetActivities', [("roomid", room_handle)])
+
+ # pubsub activity iq
+ event = q.expect('stream-iq')
+ acknowledge_iq(stream, event.stanza)
+
+ event = q.expect('dbus-return', method='SetActivities')
+
+ # make activity public
+ call_async(q, act_prop_iface, 'SetProperties',
+ 1, {'title': 'My test activity', 'private': False})
+
+ # pseudo invite
+ event = q.expect('stream-message', to='gadget.localhost')
+ message = event.stanza
+ properties = xpath.queryForNodes('/message/properties', message)
+ assert (properties is not None and len(properties) == 1), repr(properties)
+ assert properties[0].uri == 'http://laptop.org/xmpp/activity-properties'
+ assert properties[0]['room'] == 'myroom at conference.localhost'
+ assert properties[0]['activity'] == 'roomid'
+
+ # invite
+ event = q.expect('stream-message', to='myroom at conference.localhost')
+ message = event.stanza
+ x = xpath.queryForNodes('/message/x', message)
+ assert (x is not None and len(x) == 1), repr(x)
+ assert x[0].uri == 'http://jabber.org/protocol/muc#user'
+
+ invites = xpath.queryForNodes('/x/invite', x[0])
+ assert (invites is not None and len(invites) == 1), repr(invites)
+ assert invites[0]['to'] == 'gadget.localhost'
+
+ # pubsub activity prop iq
+ event = q.expect('stream-iq')
+ acknowledge_iq(stream, event.stanza)
+
+ # pubsub activity iq
+ event = q.expect('stream-iq')
+ acknowledge_iq(stream, event.stanza)
+
+
+ event = q.expect('dbus-return', method='SetProperties')
+
+if __name__ == '__main__':
+ exec_test(test)
--
1.5.6.5
More information about the Telepathy-commits
mailing list