Implement inviting buddies to a private activity
This commit is contained in:
parent
37d7fc1075
commit
fbee730549
@ -694,22 +694,23 @@ class Activity(Window, gtk.Container):
|
|||||||
|
|
||||||
def _send_invites(self):
|
def _send_invites(self):
|
||||||
while self._invites_queue:
|
while self._invites_queue:
|
||||||
buddy_key = self._invites_queue.pop()
|
account_path, contact_id = self._invites_queue.pop()
|
||||||
buddy = self._pservice.get_buddy(buddy_key)
|
pservice = presenceservice.get_instance()
|
||||||
|
buddy = pservice.get_buddy(account_path, contact_id)
|
||||||
if buddy:
|
if buddy:
|
||||||
self.shared_activity.invite(
|
self.shared_activity.invite(
|
||||||
buddy, '', self._invite_response_cb)
|
buddy, '', self._invite_response_cb)
|
||||||
else:
|
else:
|
||||||
logging.error('Cannot invite %s, no such buddy.', buddy_key)
|
logging.error('Cannot invite %s, no such buddy.', buddy_key)
|
||||||
|
|
||||||
def invite(self, buddy_key):
|
def invite(self, account_path, contact_id):
|
||||||
"""Invite a buddy to join this Activity.
|
"""Invite a buddy to join this Activity.
|
||||||
|
|
||||||
Side Effects:
|
Side Effects:
|
||||||
Calls self.share(True) to privately share the activity if it wasn't
|
Calls self.share(True) to privately share the activity if it wasn't
|
||||||
shared before.
|
shared before.
|
||||||
"""
|
"""
|
||||||
self._invites_queue.append(buddy_key)
|
self._invites_queue.append((account_path, contact_id))
|
||||||
|
|
||||||
if (self.shared_activity is None
|
if (self.shared_activity is None
|
||||||
or not self.shared_activity.props.joined):
|
or not self.shared_activity.props.joined):
|
||||||
|
@ -67,8 +67,8 @@ class ActivityService(dbus.service.Object):
|
|||||||
self._activity.props.active = active
|
self._activity.props.active = active
|
||||||
|
|
||||||
@dbus.service.method(_ACTIVITY_INTERFACE)
|
@dbus.service.method(_ACTIVITY_INTERFACE)
|
||||||
def Invite(self, buddy_key):
|
def Invite(self, account_path, contact_id):
|
||||||
self._activity.invite(buddy_key)
|
self._activity.invite(account_path, contact_id)
|
||||||
|
|
||||||
@dbus.service.method(_ACTIVITY_INTERFACE)
|
@dbus.service.method(_ACTIVITY_INTERFACE)
|
||||||
def HandleViewSource(self):
|
def HandleViewSource(self):
|
||||||
|
@ -288,14 +288,19 @@ class Activity(gobject.GObject):
|
|||||||
The callback will be called with one parameter: None on success,
|
The callback will be called with one parameter: None on success,
|
||||||
or an exception on failure.
|
or an exception on failure.
|
||||||
"""
|
"""
|
||||||
op = buddy.object_path()
|
if not self._joined:
|
||||||
_logger.debug('%r: inviting %s', self, op)
|
raise RuntimeError('Cannot invite a buddy to an activity that is'
|
||||||
self._activity.Invite(op, message,
|
'not shared.')
|
||||||
reply_handler=lambda: response_cb(None),
|
self.telepathy_text_chan.AddMembers([buddy.contact_handle], message,
|
||||||
error_handler=response_cb)
|
dbus_interface=CHANNEL_INTERFACE_GROUP,
|
||||||
|
reply_handler=partial(self.__invite_cb, response_cb),
|
||||||
|
error_handler=partial(self.__invite_cb, response_cb))
|
||||||
|
|
||||||
|
def __invite_cb(self, response_cb, error=None):
|
||||||
|
response_cb(error)
|
||||||
|
|
||||||
def set_up_tubes(self, reply_handler, error_handler):
|
def set_up_tubes(self, reply_handler, error_handler):
|
||||||
pass
|
raise NotImplementedError()
|
||||||
|
|
||||||
def __joined_cb(self, join_command, error):
|
def __joined_cb(self, join_command, error):
|
||||||
_logger.debug('%r: Join finished %r', self, error)
|
_logger.debug('%r: Join finished %r', self, error)
|
||||||
@ -378,9 +383,9 @@ class Activity(gobject.GObject):
|
|||||||
properties = {}
|
properties = {}
|
||||||
|
|
||||||
if self._color is not None:
|
if self._color is not None:
|
||||||
properties['color'] = self._color
|
properties['color'] = str(self._color)
|
||||||
if self._name is not None:
|
if self._name is not None:
|
||||||
properties['name'] = self._name
|
properties['name'] = str(self._name)
|
||||||
if self._type is not None:
|
if self._type is not None:
|
||||||
properties['type'] = self._type
|
properties['type'] = self._type
|
||||||
if self._tags is not None:
|
if self._tags is not None:
|
||||||
|
@ -21,14 +21,19 @@ STABLE.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
import gtk
|
import gtk
|
||||||
import dbus
|
import dbus
|
||||||
import gconf
|
import gconf
|
||||||
from telepathy.interfaces import CONNECTION_INTERFACE_ALIASING, \
|
from telepathy.interfaces import ACCOUNT, \
|
||||||
|
CONNECTION, \
|
||||||
|
CONNECTION_INTERFACE_ALIASING, \
|
||||||
CONNECTION_INTERFACE_CONTACTS
|
CONNECTION_INTERFACE_CONTACTS
|
||||||
|
from telepathy.constants import HANDLE_TYPE_CONTACT
|
||||||
|
|
||||||
|
ACCOUNT_MANAGER_SERVICE = 'org.freedesktop.Telepathy.AccountManager'
|
||||||
CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
|
CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
|
||||||
|
|
||||||
_logger = logging.getLogger('sugar.presence.buddy')
|
_logger = logging.getLogger('sugar.presence.buddy')
|
||||||
@ -247,31 +252,45 @@ class BaseBuddy(gobject.GObject):
|
|||||||
|
|
||||||
class Buddy(BaseBuddy):
|
class Buddy(BaseBuddy):
|
||||||
__gtype_name__ = 'PresenceBuddy'
|
__gtype_name__ = 'PresenceBuddy'
|
||||||
def __init__(self, connection, contact_handle):
|
def __init__(self, account_path, contact_id):
|
||||||
|
_logger.debug('Buddy.__init__')
|
||||||
BaseBuddy.__init__(self)
|
BaseBuddy.__init__(self)
|
||||||
|
|
||||||
self._contact_handle = contact_handle
|
self._account_path = account_path
|
||||||
|
self.contact_id = contact_id
|
||||||
|
self.contact_handle = None
|
||||||
|
|
||||||
|
_logger.info('KILL_PS Handle the connection going away and coming back')
|
||||||
|
|
||||||
|
bus = dbus.Bus()
|
||||||
|
obj = bus.get_object(ACCOUNT_MANAGER_SERVICE, account_path)
|
||||||
|
connection_path = obj.Get(ACCOUNT, 'Connection')
|
||||||
|
connection_name = connection_path.replace('/', '.')[1:]
|
||||||
|
|
||||||
|
obj = bus.get_object(connection_name, connection_path)
|
||||||
|
handles = obj.RequestHandles(HANDLE_TYPE_CONTACT, [self.contact_id],
|
||||||
|
dbus_interface=CONNECTION)
|
||||||
|
self.contact_handle = handles[0]
|
||||||
|
|
||||||
bus = dbus.SessionBus()
|
|
||||||
self._get_properties_call = bus.call_async(
|
self._get_properties_call = bus.call_async(
|
||||||
connection.requested_bus_name,
|
connection_name,
|
||||||
connection.object_path,
|
connection_path,
|
||||||
CONN_INTERFACE_BUDDY_INFO,
|
CONN_INTERFACE_BUDDY_INFO,
|
||||||
'GetProperties',
|
'GetProperties',
|
||||||
'u',
|
'u',
|
||||||
(self._contact_handle,),
|
(self.contact_handle,),
|
||||||
reply_handler=self.__got_properties_cb,
|
reply_handler=self.__got_properties_cb,
|
||||||
error_handler=self.__error_handler_cb,
|
error_handler=self.__error_handler_cb,
|
||||||
utf8_strings=True,
|
utf8_strings=True,
|
||||||
byte_arrays=True)
|
byte_arrays=True)
|
||||||
|
|
||||||
self._get_attributes_call = bus.call_async(
|
self._get_attributes_call = bus.call_async(
|
||||||
connection.requested_bus_name,
|
connection_name,
|
||||||
connection.object_path,
|
connection_path,
|
||||||
CONNECTION_INTERFACE_CONTACTS,
|
CONNECTION_INTERFACE_CONTACTS,
|
||||||
'GetContactAttributes',
|
'GetContactAttributes',
|
||||||
'auasb',
|
'auasb',
|
||||||
([self._contact_handle], [CONNECTION_INTERFACE_ALIASING], False),
|
([self.contact_handle], [CONNECTION_INTERFACE_ALIASING], False),
|
||||||
reply_handler=self.__got_attributes_cb,
|
reply_handler=self.__got_attributes_cb,
|
||||||
error_handler=self.__error_handler_cb)
|
error_handler=self.__error_handler_cb)
|
||||||
|
|
||||||
@ -283,7 +302,7 @@ class Buddy(BaseBuddy):
|
|||||||
def __got_attributes_cb(self, attributes):
|
def __got_attributes_cb(self, attributes):
|
||||||
_logger.debug('__got_attributes_cb %r', attributes)
|
_logger.debug('__got_attributes_cb %r', attributes)
|
||||||
self._get_attributes_call = None
|
self._get_attributes_call = None
|
||||||
self._update_attributes(attributes[self._contact_handle])
|
self._update_attributes(attributes[self.contact_handle])
|
||||||
|
|
||||||
def __error_handler_cb(self, error):
|
def __error_handler_cb(self, error):
|
||||||
_logger.debug('__error_handler_cb %r', error)
|
_logger.debug('__error_handler_cb %r', error)
|
||||||
|
@ -32,6 +32,7 @@ from sugar.presence.buddy import Buddy, Owner
|
|||||||
from sugar.presence.activity import Activity
|
from sugar.presence.activity import Activity
|
||||||
from sugar.presence.util import get_connection_manager
|
from sugar.presence.util import get_connection_manager
|
||||||
|
|
||||||
|
from telepathy.constants import HANDLE_TYPE_CONTACT
|
||||||
|
|
||||||
_logger = logging.getLogger('sugar.presence.presenceservice')
|
_logger = logging.getLogger('sugar.presence.presenceservice')
|
||||||
|
|
||||||
@ -314,23 +315,16 @@ class PresenceService(gobject.GObject):
|
|||||||
error_handler=lambda e: \
|
error_handler=lambda e: \
|
||||||
self._get_buddies_error_cb(error_handler, e))
|
self._get_buddies_error_cb(error_handler, e))
|
||||||
|
|
||||||
def get_buddy(self, key):
|
def get_buddy(self, account_path, contact_id):
|
||||||
"""Retrieve single Buddy object for the given public key
|
logging.info('KILL_PS decide how to invalidate this cache')
|
||||||
|
if (account_path, contact_id) in self._buddy_cache:
|
||||||
|
return self._buddy_cache[(account_path, contact_id)]
|
||||||
|
|
||||||
key -- buddy's public encryption key
|
buddy = Buddy(account_path, contact_id)
|
||||||
|
self._buddy_cache[(account_path, contact_id)] = buddy
|
||||||
returns single Buddy object or None if the activity
|
return buddy
|
||||||
is not found using GetBuddyByPublicKey on the
|
|
||||||
service
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
buddy_op = self._ps.GetBuddyByPublicKey(dbus.ByteArray(key))
|
|
||||||
except dbus.exceptions.DBusException:
|
|
||||||
_logger.exception('Unable to retrieve buddy handle for %r from '
|
|
||||||
'presence service', key)
|
|
||||||
return None
|
|
||||||
return self._new_object(buddy_op)
|
|
||||||
|
|
||||||
|
# DEPRECATED
|
||||||
def get_buddy_by_telepathy_handle(self, tp_conn_name, tp_conn_path,
|
def get_buddy_by_telepathy_handle(self, tp_conn_name, tp_conn_path,
|
||||||
handle):
|
handle):
|
||||||
"""Retrieve single Buddy object for the given public key
|
"""Retrieve single Buddy object for the given public key
|
||||||
@ -346,15 +340,22 @@ class PresenceService(gobject.GObject):
|
|||||||
channel-specific handle.
|
channel-specific handle.
|
||||||
:Returns: the Buddy object, or None if the buddy is not found
|
:Returns: the Buddy object, or None if the buddy is not found
|
||||||
"""
|
"""
|
||||||
logging.info('KILL_PS decide how to invalidate this cache')
|
|
||||||
if (tp_conn_path, handle) in self._buddy_cache:
|
bus = dbus.Bus()
|
||||||
return self._buddy_cache[(tp_conn_path, handle)]
|
obj = bus.get_object(ACCOUNT_MANAGER_SERVICE, ACCOUNT_MANAGER_PATH)
|
||||||
else:
|
account_manager = dbus.Interface(obj, ACCOUNT_MANAGER)
|
||||||
bus = dbus.SessionBus()
|
account_paths = account_manager.Get(ACCOUNT_MANAGER, 'ValidAccounts',
|
||||||
connection = bus.get_object(tp_conn_name, tp_conn_path)
|
dbus_interface=PROPERTIES_IFACE)
|
||||||
buddy = Buddy(connection, handle)
|
for account_path in account_paths:
|
||||||
self._buddy_cache[(tp_conn_path, handle)] = buddy
|
obj = bus.get_object(ACCOUNT_MANAGER_SERVICE, account_path)
|
||||||
return buddy
|
connection_path = obj.Get(ACCOUNT, 'Connection')
|
||||||
|
if connection_path == tp_conn_path:
|
||||||
|
connection_name = connection_path.replace('/', '.')[1:]
|
||||||
|
connection = bus.get_object(connection_name, connection_path)
|
||||||
|
contact_ids = connection.InspectHandles(HANDLE_TYPE_CONTACT, [handle])
|
||||||
|
return self.get_buddy(account_path, contact_ids[0])
|
||||||
|
|
||||||
|
raise ValueError('Unknown buddy in connection %s with handle %d', tp_conn_path, handle)
|
||||||
|
|
||||||
def get_owner(self):
|
def get_owner(self):
|
||||||
"""Retrieves the laptop Buddy object."""
|
"""Retrieves the laptop Buddy object."""
|
||||||
|
Loading…
Reference in New Issue
Block a user