Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2007-06-08 11:40:58 (GMT)
committer Simon McVittie <simon.mcvittie@collabora.co.uk>2007-06-08 11:40:58 (GMT)
commit5741a079edae63de0c2a06b9bd037dc5f68cedf2 (patch)
tree0c3ab0209b656dbbdcb465a15b4149e94def3123
parent52b8a7428a5c8da342b5ea50afd0432a5ef46d73 (diff)
server_plugin, activity: Move remaining activity-joining mechanics from server_plugin to activity
-rw-r--r--src/activity.py32
-rw-r--r--src/server_plugin.py46
2 files changed, 30 insertions, 48 deletions
diff --git a/src/activity.py b/src/activity.py
index 153d2e1..40c3ed9 100644
--- a/src/activity.py
+++ b/src/activity.py
@@ -24,8 +24,9 @@ import logging
from telepathy.client import Channel
from telepathy.constants import (CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES,
- PROPERTY_FLAG_WRITE)
+ PROPERTY_FLAG_WRITE, HANDLE_TYPE_ROOM)
from telepathy.interfaces import (CHANNEL_INTERFACE, CHANNEL_INTERFACE_GROUP,
+ CHANNEL_TYPE_TEXT, CONN_INTERFACE,
PROPERTIES_INTERFACE)
@@ -569,9 +570,7 @@ class Activity(ExportedGObject):
else:
self._joined_cb(channel)
- def _join_activity_create_channel_cb(self, handle, chan_path):
- self._room = handle
-
+ def _join_activity_create_channel_cb(self, chan_path):
channel = Channel(self._tp.get_connection().service_name, chan_path)
channel[PROPERTIES_INTERFACE].ListProperties(
reply_handler=lambda prop_specs:
@@ -579,6 +578,17 @@ class Activity(ExportedGObject):
channel, prop_specs),
error_handler=self._join_failed_cb)
+ def _join_activity_got_handles_cb(self, handles):
+ assert len(handles) == 1
+
+ self._room = handles[0]
+
+ conn = self._tp.get_connection()
+ conn[CONN_INTERFACE].RequestChannel(CHANNEL_TYPE_TEXT,
+ HANDLE_TYPE_ROOM, self._room, True,
+ reply_handler=self._join_activity_create_channel_cb,
+ error_handler=self._join_failed_cb)
+
def join(self, async_cb, async_err_cb, sharing):
"""Local method for the local user to attempt to join the activity.
@@ -607,8 +617,18 @@ class Activity(ExportedGObject):
self._join_err_cb = async_err_cb
self._join_is_sharing = sharing
- self._tp.join_activity(self._id, self._join_activity_create_channel_cb,
- self._join_failed_cb)
+ if self._room:
+ # we're probably sharing a local activity.
+ # FIXME: assert that this is the case?
+ self._join_activity_got_handles_cb((self._room,))
+ else:
+ conn = self._tp.get_connection()
+
+ conn[CONN_INTERFACE].RequestHandles(HANDLE_TYPE_ROOM,
+ [self._tp.suggest_room_for_activity(self._id)],
+ reply_handler=self._join_activity_got_handles_cb,
+ error_handler=self._join_failed_cb)
+
_logger.debug("triggered share/join attempt on activity %s", self._id)
def get_channels(self):
diff --git a/src/server_plugin.py b/src/server_plugin.py
index 053170b..160e9fa 100644
--- a/src/server_plugin.py
+++ b/src/server_plugin.py
@@ -472,49 +472,11 @@ class ServerPlugin(gobject.GObject):
self._joined_activities.append((activity_id, room))
self._set_self_activities()
- def _join_activity_get_channel_cb(self, activity_id, callback, err_cb,
- handles):
- if not self._activities.has_key(activity_id):
- self._activities[activity_id] = handles[0]
-
- if (activity_id, handles[0]) in self._joined_activities:
- e = RuntimeError("Already joined activity %s" % activity_id)
- _logger.debug('%s', e)
- err_cb(e)
- return
-
- self._conn[CONN_INTERFACE].RequestChannel(CHANNEL_TYPE_TEXT,
- HANDLE_TYPE_ROOM, handles[0], True,
- reply_handler=lambda path: callback(handles[0], path),
- error_handler=err_cb)
-
- def join_activity(self, activity_id, callback, err_cb):
- """Share activity with the network, or join an activity on the
- network (or locally)
-
- activity_id -- unique ID for the activity
- callback -- callback to be called when the join succeeds or fails,
- with arguments:
- activity room handle: int or long
- channel: object path
- err_cb -- callback to be called on failure, with one Exception argument
-
- Asks the Telepathy server to create a "conference" channel
- for the activity or return a handle to an already created
- conference channel for the activity.
+ def suggest_room_for_activity(self, activity_id):
+ """Suggest a room to use to share the given activity.
"""
- handle = self._activities.get(activity_id)
- if not handle:
- # FIXME: figure out why the server can't figure this out itself
- room_jid = activity_id + "@conference." + self._account["server"]
- self._conn[CONN_INTERFACE].RequestHandles(HANDLE_TYPE_ROOM,
- [room_jid],
- reply_handler=lambda *args: self._join_activity_get_channel_cb(
- activity_id, callback, err_cb, *args),
- error_handler=err_cb)
- else:
- self._join_activity_get_channel_cb(activity_id, callback, err_cb,
- [handle])
+ # FIXME: figure out why the server can't figure this out itself
+ return activity_id + '@conference.' + self._account['server']
def _ignore_success_cb(self):
"""Ignore an event (null-operation)"""