Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/model
diff options
context:
space:
mode:
authorMorgan Collett <morgan.collett@gmail.com>2008-05-28 20:16:23 (GMT)
committer Morgan Collett <morgan.collett@gmail.com>2008-06-13 14:59:34 (GMT)
commit9d89b4c0c07d5e337ff98a8aeedd6adcea8e96c8 (patch)
tree1c1ef1e2d7030c70dbd318130867e318e24cac5e /src/model
parent7a62df6758254ee9b6bb764c1ccccb9b40627131 (diff)
6298: Refactor invites to handle 1-1 XMPP connections
Diffstat (limited to 'src/model')
-rw-r--r--src/model/Invites.py67
-rw-r--r--src/model/Owner.py21
2 files changed, 70 insertions, 18 deletions
diff --git a/src/model/Invites.py b/src/model/Invites.py
index 9ffab44..0f2c050 100644
--- a/src/model/Invites.py
+++ b/src/model/Invites.py
@@ -17,11 +17,11 @@
import gobject
from sugar.presence import presenceservice
-class Invite:
- def __init__(self, issuer, bundle_id, activity_id):
- self._issuer = issuer
- self._activity_id = activity_id
- self._bundle_id = bundle_id
+
+class BaseInvite:
+ """Invitation to shared activity or private 1-1 Telepathy channel"""
+ def __init__(self):
+ self._activity_id = None
def get_activity_id(self):
return self._activity_id
@@ -29,6 +29,38 @@ class Invite:
def get_bundle_id(self):
return self._bundle_id
+
+class ActivityInvite(BaseInvite):
+ """Invitation to a shared activity."""
+ def __init__(self, bundle_id, activity_id):
+ self._activity_id = activity_id
+ self._bundle_id = bundle_id
+
+
+class PrivateInvite(BaseInvite):
+ """Invitation to a private 1-1 Telepathy channel.
+
+ This includes text chat or streaming media.
+ """
+ def __init__(self, bundle_id, private_channel):
+ """init for PrivateInvite.
+
+ bundle_id: string, e.g. 'org.laptop.Chat'
+ private_channel: string containing simplejson dump of Telepathy
+ bus, connection and channel
+
+ Note: self_activity_id is set to None to differentiate between
+ PrivateInvites and ActivityInvites
+ """
+ self._activity_id = None
+ self._bundle_id = bundle_id
+ self._private_channel = private_channel
+
+ def get_private_channel(self):
+ """Telepathy channel info from private invitation"""
+ return self._private_channel
+
+
class Invites(gobject.GObject):
__gsignals__ = {
'invite-added': (gobject.SIGNAL_RUN_FIRST,
@@ -46,18 +78,32 @@ class Invites(gobject.GObject):
owner = ps.get_owner()
owner.connect('joined-activity', self._owner_joined_cb)
- def add_invite(self, issuer, bundle_id, activity_id):
+ def add_invite(self, bundle_id, activity_id):
if activity_id in self._dict:
# there is no point to add more than one time
# an invite for the same activity
return
- invite = Invite(issuer, bundle_id, activity_id)
+ invite = ActivityInvite(bundle_id, activity_id)
self._dict[activity_id] = invite
self.emit('invite-added', invite)
+ def add_private_invite(self, private_channel, bundle_id):
+ if private_channel in self._dict:
+ # there is no point to add more than one invite for the
+ # same incoming connection
+ return
+
+ invite = PrivateInvite(bundle_id, private_channel)
+ self._dict[private_channel] = invite
+ self.emit('invite-added', invite)
+
def remove_invite(self, invite):
- self._dict.pop(invite.get_activity_id())
+ del self._dict[invite.get_activity_id()]
+ self.emit('invite-removed', invite)
+
+ def remove_private_invite(self, invite):
+ del self._dict[invite.get_private_channel()]
self.emit('invite-removed', invite)
def remove_activity(self, activity_id):
@@ -65,6 +111,11 @@ class Invites(gobject.GObject):
if invite is not None:
self.remove_invite(invite)
+ def remove_private_channel(self, private_channel):
+ invite = self._dict.get(private_channel)
+ if invite is not None:
+ self.remove_private_invite(invite)
+
def _owner_joined_cb(self, owner, activity):
self.remove_activity(activity.props.id)
diff --git a/src/model/Owner.py b/src/model/Owner.py
index 7affb83..0132425 100644
--- a/src/model/Owner.py
+++ b/src/model/Owner.py
@@ -17,6 +17,7 @@
import gobject
import os
+import simplejson
from telepathy.interfaces import CHANNEL_TYPE_TEXT
@@ -81,7 +82,7 @@ class ShellOwner(gobject.GObject):
return self._nick
def _activity_invitation_cb(self, pservice, activity, buddy, message):
- self._invites.add_invite(buddy, activity.props.type,
+ self._invites.add_invite(activity.props.type,
activity.props.id)
def _private_invitation_cb(self, pservice, bus_name, connection,
@@ -89,16 +90,16 @@ class ShellOwner(gobject.GObject):
"""Handle a private-invitation from Presence Service.
This is a connection by a non-Sugar XMPP client, so
- launch Chat with the Telepathy connection and channel.
+ launch Chat or VideoChat with the Telepathy connection and
+ channel.
"""
- import json
- from sugar import activity
- from sugar.activity import activityfactory
- tp_channel = json.write([str(bus_name), str(connection),
- str(channel)])
- registry = activity.get_registry()
- if registry.get_activity('org.laptop.Chat') and channel_type == CHANNEL_TYPE_TEXT:
- activityfactory.create_with_uri('org.laptop.Chat', tp_channel)
+ if channel_type == CHANNEL_TYPE_TEXT:
+ bundle_id = 'org.laptop.Chat'
+ else:
+ bundle_id = 'org.laptop.VideoChat'
+ tp_channel = simplejson.dumps([str(bus_name), str(connection),
+ str(channel)])
+ self._invites.add_private_invite(tp_channel, bundle_id)
def _activity_disappeared_cb(self, pservice, activity):
self._invites.remove_activity(activity.props.id)