Ticket #2963: 2963.patch

File 2963.patch, 11.1 KB (added by alsroot, 13 years ago)
  • src/jarabe/model/neighborhood.py

    From cc3a39d15ff7ffcc438c5fd8f7bc41eb46378ae9 Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@activitycentral.org>
    Date: Thu, 14 Jul 2011 03:15:53 +0000
    Subject: [PATCH sugar] Sugar telepathy code does not take into account
     presence status of buddies #2963
    
    ---
     src/jarabe/model/neighborhood.py |   60 +++++++++++++++++++++++++------------
     1 files changed, 40 insertions(+), 20 deletions(-)
    
    diff --git a/src/jarabe/model/neighborhood.py b/src/jarabe/model/neighborhood.py
    index f27e2be..7f0d0ab 100644
    a b from telepathy.interfaces import ACCOUNT, \ 
    3838from telepathy.constants import HANDLE_TYPE_CONTACT, \
    3939                                HANDLE_TYPE_LIST, \
    4040                                CONNECTION_PRESENCE_TYPE_OFFLINE, \
     41                                CONNECTION_PRESENCE_TYPE_AVAILABLE, \
    4142                                CONNECTION_STATUS_CONNECTED, \
    4243                                CONNECTION_STATUS_DISCONNECTED
    4344from telepathy.client import Connection, Channel
    class _Account(gobject.GObject): 
    258259        self._connection = Connection(connection_name, connection_path,
    259260                                      ready_handler=self.__connection_ready_cb)
    260261
     262        def new_channel_cb(object_path, channel_type, handle_type, handle,
     263                suppress_handler):
     264            if handle_type == HANDLE_TYPE_LIST and \
     265                    channel_type == CHANNEL_TYPE_CONTACT_LIST and \
     266                    object_path.split('/')[-1] in ['subscribe', 'publish']:
     267                channel = Channel(self._connection.service_name, object_path)
     268                channel[PROPERTIES_IFACE].Get(CHANNEL_INTERFACE_GROUP,
     269                        'Members',
     270                        reply_handler=self.__get_members_ready_cb,
     271                        error_handler=partial(self.__error_handler_cb,
     272                                              'Connection.GetMembers'))
     273
     274        self._connection[CONNECTION].connect_to_signal('NewChannel',
     275                new_channel_cb)
     276
    261277    def __connection_ready_cb(self, connection):
    262278        logging.debug('_Account.__connection_ready_cb %r',
    263279                      connection.object_path)
    class _Account(gobject.GObject): 
    365381        is_ours, channel_path, properties = \
    366382                connection.EnsureChannel(properties)
    367383
    368         channel = Channel(self._connection.service_name, channel_path)
    369         channel[CHANNEL_INTERFACE_GROUP].connect_to_signal(
    370                   'MembersChanged', self.__members_changed_cb)
    371 
    372         channel[PROPERTIES_IFACE].Get(CHANNEL_INTERFACE_GROUP,
    373                 'Members',
    374                 reply_handler=self.__get_members_ready_cb,
    375                 error_handler=partial(self.__error_handler_cb,
    376                                       'Connection.GetMembers'))
    377 
    378384    def __update_capabilities_cb(self):
    379385        pass
    380386
    class _Account(gobject.GObject): 
    390396
    391397    def __presences_changed_cb(self, presences):
    392398        logging.debug('_Account.__presences_changed_cb %r', presences)
     399
     400        added_handles = []
     401
    393402        for handle, presence in presences.iteritems():
    394             if handle in self._buddy_handles:
    395                 presence_type, status_, message_ = presence
     403            presence_type, status_, message_ = presence
     404            if handle in self._buddy_handles and \
     405                    self._buddy_handles[handle] is not None:
    396406                if presence_type == CONNECTION_PRESENCE_TYPE_OFFLINE:
    397407                    contact_id = self._buddy_handles[handle]
    398408                    del self._buddy_handles[handle]
    399409                    self.emit('buddy-removed', contact_id)
     410            elif presence_type == CONNECTION_PRESENCE_TYPE_AVAILABLE:
     411                added_handles.append(handle)
     412
     413        if added_handles:
     414            self._add_buddy_handles(added_handles)
    400415
    401416    def __buddy_info_updated_cb(self, handle, properties):
    402417        logging.debug('_Account.__buddy_info_updated_cb %r', handle)
     418        if handle not in self._buddy_handles:
     419            # TODO Is it ok if we got PropertiesChanged for unknown buddy
     420            return
    403421        self.emit('buddy-updated', self._buddy_handles[handle], properties)
    404422
    405423    def __current_activity_changed_cb(self, contact_handle, activity_id,
    class _Account(gobject.GObject): 
    521539                    error_handler=partial(self.__error_handler_cb,
    522540                                          'BuddyInfo.Getactivities'))
    523541
    524     def __members_changed_cb(self, message, added, removed, local_pending,
    525                              remote_pending, actor, reason):
    526         self._add_buddy_handles(added)
    527 
    528542    def __get_members_ready_cb(self, handles):
    529         logging.debug('_Account.__get_members_ready_cb %r', handles)
    530         if not handles:
    531             return
     543        connection = self._connection[CONNECTION_INTERFACE_SIMPLE_PRESENCE]
     544        online_handles = []
     545
     546        for handle, presence in connection.GetPresences(handles).items():
     547            presence_type, status_, message_ = presence
     548            if presence_type == CONNECTION_PRESENCE_TYPE_AVAILABLE:
     549                online_handles.append(handle)
    532550
    533         self._add_buddy_handles(handles)
     551        if online_handles:
     552            logging.debug('_Account.__get_members_ready_cb %r', online_handles)
     553            self._add_buddy_handles(online_handles)
    534554
    535555    def _add_buddy_handles(self, handles):
    536556        logging.debug('_Account._add_buddy_handles %r', handles)
  • src/jarabe/model/neighborhood.py

    -- 
    1.7.5.rc1
    
    From 17f44f111411a6fcb91a87f686ce2a622f26513d Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@activitycentral.org>
    Date: Sun, 17 Jul 2011 03:53:55 +0000
    Subject: [PATCH sugar 1/2] Add unknown buddies on prop updates and emit
     update signal after adding new buddies to not
     lost this info
    
    ---
     src/jarabe/model/neighborhood.py |   41 +++++++++++++++++++------------------
     1 files changed, 21 insertions(+), 20 deletions(-)
    
    diff --git a/src/jarabe/model/neighborhood.py b/src/jarabe/model/neighborhood.py
    index 7dbc4af..9a86550 100644
    a b class _Account(gobject.GObject): 
    431431
    432432    def __buddy_info_updated_cb(self, handle, properties):
    433433        logging.debug('_Account.__buddy_info_updated_cb %r', handle)
    434         if handle not in self._buddy_handles:
    435             # TODO Is it ok if we got PropertiesChanged for unknown buddy
    436             return
    437         self.emit('buddy-updated', self._buddy_handles[handle], properties)
     434
     435        if handle in self._buddy_handles:
     436            self.emit('buddy-updated', self._buddy_handles[handle], properties)
     437        else:
     438            self._add_buddy_handles([handle])
    438439
    439440    def __current_activity_changed_cb(self, contact_handle, activity_id,
    440441                                      room_handle):
    class _Account(gobject.GObject): 
    556557                                          'BuddyInfo.Getactivities'))
    557558
    558559    def __get_members_ready_cb(self, handles):
     560        self._add_buddy_handles(handles)
     561
     562    def _add_buddy_handles(self, handles):
    559563        connection = self._connection[CONNECTION_INTERFACE_SIMPLE_PRESENCE]
    560564        online_handles = []
    561565
    class _Account(gobject.GObject): 
    564568            if presence_type == CONNECTION_PRESENCE_TYPE_AVAILABLE:
    565569                online_handles.append(handle)
    566570
    567         if online_handles:
    568             logging.debug('_Account.__get_members_ready_cb %r', online_handles)
    569             self._add_buddy_handles(online_handles)
     571        if not online_handles:
     572            return
    570573
    571     def _add_buddy_handles(self, handles):
    572         logging.debug('_Account._add_buddy_handles %r', handles)
     574        logging.debug('_Account._add_buddy_handles %r', online_handles)
    573575        interfaces = [CONNECTION, CONNECTION_INTERFACE_ALIASING]
    574576        self._connection[CONNECTION_INTERFACE_CONTACTS].GetContactAttributes(
    575                 handles, interfaces, False,
    576                 reply_handler=self.__get_contact_attributes_cb,
     577                online_handles, interfaces, False,
     578                reply_handler=partial(self.__get_contact_attributes_cb),
    577579                error_handler=partial(self.__error_handler_cb,
    578580                                      'Contacts.GetContactAttributes'))
    579581
    class _Account(gobject.GObject): 
    589591
    590592        def error_handler(error):
    591593            if tries <= 1:
    592                 raise RuntimeError('No luck with %s: %s' % (meth, error))
     594                logging.error('No luck with %s: %s', meth, error)
     595                return
    593596            logging.debug('Try to call %r in %d seconds', meth, timeout)
    594597            gobject.timeout_add_seconds(timeout, self._call_buddy,
    595598                    meth, handle, cb, args, tries - 1, timeout * 2)
    class _Account(gobject.GObject): 
    612615                              ' do not add ourself %r', handle)
    613616                continue
    614617
    615             if handle in self._buddy_handles and \
    616                     not self._buddy_handles[handle] is None:
    617                 logging.debug('Got handle %r with nick %r, going to update',
    618                               handle, nick)
    619                 self.emit('buddy-updated', self._buddy_handles[handle],
    620                           attributes[handle])
    621             else:
     618            if handle not in self._buddy_handles or \
     619                    self._buddy_handles[handle] is None:
    622620                logging.debug('Got handle %r with nick %r, going to add',
    623621                              handle, nick)
    624622
    class _Account(gobject.GObject): 
    638636
    639637                self.emit('buddy-added', contact_id, nick, handle)
    640638
     639            self.emit('buddy-updated', self._buddy_handles[handle],
     640                      attributes[handle])
     641
    641642    def __got_activities_cb(self, buddy_handle, activities):
    642643        logging.debug('_Account.__got_activities_cb %r %r', buddy_handle,
    643644                      activities)
    class Neighborhood(gobject.GObject): 
    889890        self._buddies[contact_id] = buddy
    890891
    891892    def __buddy_updated_cb(self, account, contact_id, properties):
    892         logging.debug('__buddy_updated_cb %r', contact_id)
     893        logging.debug('__buddy_updated_cb %r %r', contact_id, properties)
    893894        if contact_id is None:
    894895            # Don't know the contact-id yet, will get the full state later
    895896            return
  • src/jarabe/model/neighborhood.py

    -- 
    1.7.5.rc1
    
    
    From b798fc58ad044d803f07220f52075163b65c6d82 Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@activitycentral.org>
    Date: Sun, 17 Jul 2011 18:23:41 +0000
    Subject: [PATCH sugar 2/2] Buddy alias change doesn't update nick
    
    ---
     src/jarabe/model/neighborhood.py |    4 ++++
     1 files changed, 4 insertions(+), 0 deletions(-)
    
    diff --git a/src/jarabe/model/neighborhood.py b/src/jarabe/model/neighborhood.py
    index 9a86550..8405869 100644
    a b class Neighborhood(gobject.GObject): 
    913913        if 'nick' in properties:
    914914            buddy.props.nick = properties['nick']
    915915
     916        alias = '%s/alias' % CONNECTION_INTERFACE_ALIASING
     917        if alias in properties:
     918            buddy.props.nick = properties[alias]
     919
    916920        if is_new:
    917921            self.emit('buddy-added', buddy)
    918922