[Sugar-devel] [PATCH sugar-toolkit] Fix invitations from a non sugar client (empathy), part of OLPC #10814

Simon Schampijer simon at schampijer.de
Tue May 24 04:18:19 EDT 2011


This differentiates between sugar and non sugar invitations using the
handle type. For non-sugar invitations we use the activity id to
determine which activity to join.

Signed-off-by: Simon Schampijer <simon at laptop.org>
---
 src/sugar/activity/activity.py |   38 ++++++++++++++++++++++++++------------
 1 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/src/sugar/activity/activity.py b/src/sugar/activity/activity.py
index 09ba3cc..b8603c5 100644
--- a/src/sugar/activity/activity.py
+++ b/src/sugar/activity/activity.py
@@ -280,6 +280,7 @@ class Activity(Window, gtk.Container):
         self._active = False
         self._activity_id = handle.activity_id
         self.shared_activity = None
+        self._client_handler = None
         self._join_id = None
         self._updating_jobject = False
         self._closing = False
@@ -370,7 +371,9 @@ class Activity(Window, gtk.Container):
             # There's already an instance on the mesh, join it
             logging.debug('*** Act %s joining existing mesh instance %r',
                           self._activity_id, mesh_instance)
-            self._client_handler = _ClientHandler(self.get_bundle_id(), None)
+            if self._client_handler is None:
+                self._client_handler = _ClientHandler(self.get_bundle_id(),
+                                                      None)
             self.shared_activity = mesh_instance
             self.shared_activity.connect('notify::private',
                                          self.__privacy_changed_cb)
@@ -392,17 +395,25 @@ class Activity(Window, gtk.Container):
             else:
                 logging.debug('Unknown share scope %r', share_scope)
 
-    def __got_channel_cb(self, wait_loop, connection_path, channel_path):
+    def __got_channel_cb(self, wait_loop, connection_path, channel_path,
+                         handle_type):
         logging.debug('Activity.__got_channel_cb')
-        connection_name = connection_path.replace('/', '.')[1:]
-
-        bus = dbus.SessionBus()
-        channel = bus.get_object(connection_name, channel_path)
-        room_handle = channel.Get(CHANNEL, 'TargetHandle')
 
         pservice = presenceservice.get_instance()
-        mesh_instance = pservice.get_activity_by_handle(connection_path,
-                                                        room_handle)
+
+        if handle_type == CONNECTION_HANDLE_TYPE_ROOM:
+            connection_name = connection_path.replace('/', '.')[1:]
+
+            bus = dbus.SessionBus()
+            channel = bus.get_object(connection_name, channel_path)
+            room_handle = channel.Get(CHANNEL, 'TargetHandle')
+
+            mesh_instance = pservice.get_activity_by_handle(connection_path,
+                                                            room_handle)
+        else:
+            mesh_instance = pservice.get_activity(self._activity_id,
+                                                  warn_if_none=False)
+
         self._set_up_sharing(mesh_instance, SCOPE_PRIVATE)
         wait_loop.quit()
 
@@ -954,13 +965,16 @@ class _ClientHandler(dbus.service.Object, DBusProperties):
         logging.debug('HandleChannels\n\t%r\n\t%r\n\t%r\n\t%r\n\t%r\n\t%r',
                 account, connection, channels, requests_satisfied,
                 user_action_time, handler_info)
+
+        if self._got_channel_cb is None:
+            return
+
         try:
             for object_path, properties in channels:
                 channel_type = properties[CHANNEL + '.ChannelType']
                 handle_type = properties[CHANNEL + '.TargetHandleType']
-                if channel_type == CHANNEL_TYPE_TEXT and \
-                   handle_type == CONNECTION_HANDLE_TYPE_ROOM:
-                    self._got_channel_cb(connection, object_path)
+                if channel_type == CHANNEL_TYPE_TEXT:
+                    self._got_channel_cb(connection, object_path, handle_type)
         except Exception, e:
             logging.exception(e)
 
-- 
1.7.4



More information about the Sugar-devel mailing list