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, \ |
38 | 38 | from telepathy.constants import HANDLE_TYPE_CONTACT, \ |
39 | 39 | HANDLE_TYPE_LIST, \ |
40 | 40 | CONNECTION_PRESENCE_TYPE_OFFLINE, \ |
| 41 | CONNECTION_PRESENCE_TYPE_AVAILABLE, \ |
41 | 42 | CONNECTION_STATUS_CONNECTED, \ |
42 | 43 | CONNECTION_STATUS_DISCONNECTED |
43 | 44 | from telepathy.client import Connection, Channel |
… |
… |
class _Account(gobject.GObject): |
258 | 259 | self._connection = Connection(connection_name, connection_path, |
259 | 260 | ready_handler=self.__connection_ready_cb) |
260 | 261 | |
| 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 | |
261 | 277 | def __connection_ready_cb(self, connection): |
262 | 278 | logging.debug('_Account.__connection_ready_cb %r', |
263 | 279 | connection.object_path) |
… |
… |
class _Account(gobject.GObject): |
365 | 381 | is_ours, channel_path, properties = \ |
366 | 382 | connection.EnsureChannel(properties) |
367 | 383 | |
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 | | |
378 | 384 | def __update_capabilities_cb(self): |
379 | 385 | pass |
380 | 386 | |
… |
… |
class _Account(gobject.GObject): |
390 | 396 | |
391 | 397 | def __presences_changed_cb(self, presences): |
392 | 398 | logging.debug('_Account.__presences_changed_cb %r', presences) |
| 399 | |
| 400 | added_handles = [] |
| 401 | |
393 | 402 | 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: |
396 | 406 | if presence_type == CONNECTION_PRESENCE_TYPE_OFFLINE: |
397 | 407 | contact_id = self._buddy_handles[handle] |
398 | 408 | del self._buddy_handles[handle] |
399 | 409 | 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) |
400 | 415 | |
401 | 416 | def __buddy_info_updated_cb(self, handle, properties): |
402 | 417 | 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 |
403 | 421 | self.emit('buddy-updated', self._buddy_handles[handle], properties) |
404 | 422 | |
405 | 423 | def __current_activity_changed_cb(self, contact_handle, activity_id, |
… |
… |
class _Account(gobject.GObject): |
521 | 539 | error_handler=partial(self.__error_handler_cb, |
522 | 540 | 'BuddyInfo.Getactivities')) |
523 | 541 | |
524 | | def __members_changed_cb(self, message, added, removed, local_pending, |
525 | | remote_pending, actor, reason): |
526 | | self._add_buddy_handles(added) |
527 | | |
528 | 542 | 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) |
532 | 550 | |
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) |
534 | 554 | |
535 | 555 | def _add_buddy_handles(self, handles): |
536 | 556 | logging.debug('_Account._add_buddy_handles %r', handles) |
--
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): |
431 | 431 | |
432 | 432 | def __buddy_info_updated_cb(self, handle, properties): |
433 | 433 | 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]) |
438 | 439 | |
439 | 440 | def __current_activity_changed_cb(self, contact_handle, activity_id, |
440 | 441 | room_handle): |
… |
… |
class _Account(gobject.GObject): |
556 | 557 | 'BuddyInfo.Getactivities')) |
557 | 558 | |
558 | 559 | def __get_members_ready_cb(self, handles): |
| 560 | self._add_buddy_handles(handles) |
| 561 | |
| 562 | def _add_buddy_handles(self, handles): |
559 | 563 | connection = self._connection[CONNECTION_INTERFACE_SIMPLE_PRESENCE] |
560 | 564 | online_handles = [] |
561 | 565 | |
… |
… |
class _Account(gobject.GObject): |
564 | 568 | if presence_type == CONNECTION_PRESENCE_TYPE_AVAILABLE: |
565 | 569 | online_handles.append(handle) |
566 | 570 | |
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 |
570 | 573 | |
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) |
573 | 575 | interfaces = [CONNECTION, CONNECTION_INTERFACE_ALIASING] |
574 | 576 | 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), |
577 | 579 | error_handler=partial(self.__error_handler_cb, |
578 | 580 | 'Contacts.GetContactAttributes')) |
579 | 581 | |
… |
… |
class _Account(gobject.GObject): |
589 | 591 | |
590 | 592 | def error_handler(error): |
591 | 593 | 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 |
593 | 596 | logging.debug('Try to call %r in %d seconds', meth, timeout) |
594 | 597 | gobject.timeout_add_seconds(timeout, self._call_buddy, |
595 | 598 | meth, handle, cb, args, tries - 1, timeout * 2) |
… |
… |
class _Account(gobject.GObject): |
612 | 615 | ' do not add ourself %r', handle) |
613 | 616 | continue |
614 | 617 | |
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: |
622 | 620 | logging.debug('Got handle %r with nick %r, going to add', |
623 | 621 | handle, nick) |
624 | 622 | |
… |
… |
class _Account(gobject.GObject): |
638 | 636 | |
639 | 637 | self.emit('buddy-added', contact_id, nick, handle) |
640 | 638 | |
| 639 | self.emit('buddy-updated', self._buddy_handles[handle], |
| 640 | attributes[handle]) |
| 641 | |
641 | 642 | def __got_activities_cb(self, buddy_handle, activities): |
642 | 643 | logging.debug('_Account.__got_activities_cb %r %r', buddy_handle, |
643 | 644 | activities) |
… |
… |
class Neighborhood(gobject.GObject): |
889 | 890 | self._buddies[contact_id] = buddy |
890 | 891 | |
891 | 892 | 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) |
893 | 894 | if contact_id is None: |
894 | 895 | # Don't know the contact-id yet, will get the full state later |
895 | 896 | return |
--
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): |
913 | 913 | if 'nick' in properties: |
914 | 914 | buddy.props.nick = properties['nick'] |
915 | 915 | |
| 916 | alias = '%s/alias' % CONNECTION_INTERFACE_ALIASING |
| 917 | if alias in properties: |
| 918 | buddy.props.nick = properties[alias] |
| 919 | |
916 | 920 | if is_new: |
917 | 921 | self.emit('buddy-added', buddy) |
918 | 922 | |