- def AddMembers(self, contacts, message):
- addressBook = self._conn.gvoice_client
- if self._handle.group is None:
- for contactHandleId in contacts:
- contactHandle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, contactHandleId)
- _moduleLogger.info("Adding contact %r to pending group %r" % (contactHandle, self._handle))
- if contactHandleId in self.__pending_remove:
- self.__pending_remove.remove(contactHandleId)
- else:
- self.__pending_add.append(contactHandleId)
- return
- else:
- for contactHandleId in contacts:
- contactHandle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, contactHandleId)
- _moduleLogger.info("Adding contact %r to group %r" % (contactHandle, self._handle))
- contact = contactHandle.contact
- group = self._handle.group
- if contact is not None:
- addressBook.add_contact_to_group(group, contact)
- else:
- contactHandle.pending_groups.add(group)
-
- def RemoveMembers(self, contacts, message):
- addressBook = self._conn.gvoice_client
- if self._handle.group is None:
- for contactHandleId in contacts:
- contactHandle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, contactHandleId)
- _moduleLogger.info("Adding contact %r to pending group %r" % (contactHandle, self._handle))
- if contactHandleId in self.__pending_add:
- self.__pending_add.remove(contactHandleId)
- else:
- self.__pending_remove.append(contactHandleId)
- return
- else:
- for contactHandleId in contacts:
- contactHandle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, contactHandleId)
- _moduleLogger.info("Removing contact %r from pending group %r" % (contactHandle, self._handle))
- contact = contactHandle.contact
- group = self._handle.group
- if contact is not None:
- addressBook.delete_contact_from_group(group, contact)
- else:
- contactHandle.pending_groups.discard(group)
+ @gobject_utils.async
+ @gtk_toolbox.log_exception(_moduleLogger)
+ def _on_contacts_refreshed(self, addressbook, added, removed, changed):
+ self._process_refresh(addressbook, added, removed)
+
+ def _process_refresh(self, addressbook, added, removed):
+ connection = self._conn
+ handlesAdded = [
+ handle.create_handle(connection, "contact", contactId, phoneNumber)
+ for contactId in added
+ for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
+ ]
+ handlesRemoved = [
+ handle.create_handle(connection, "contact", contactId, phoneNumber)
+ for contactId in removed
+ for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
+ ]
+ message = ""
+ actor = 0
+ reason = telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
+ self.MembersChanged(
+ message,
+ handlesAdded, handlesRemoved,
+ (), (),
+ actor,
+ reason,
+ )
+
+
+def create_contact_list_channel(connection, h):
+ if h.get_name() == 'subscribe':
+ # The group of contacts for whom you receive presence
+ ChannelClass = AllContactsListChannel
+ elif h.get_name() == 'publish':
+ # The group of contacts who may receive your presence
+ ChannelClass = AllContactsListChannel
+ elif h.get_name() == 'hide':
+ # A group of contacts who are on the publish list but are temporarily
+ # disallowed from receiving your presence
+ # This doesn't make sense to support
+ _moduleLogger.warn("Unsuported type %s" % h.get_name())
+ elif h.get_name() == 'allow':
+ # A group of contacts who may send you messages
+ # @todo Allow-List would be cool to support
+ _moduleLogger.warn("Unsuported type %s" % h.get_name())
+ elif h.get_name() == 'deny':
+ # A group of contacts who may not send you messages
+ # @todo Deny-List would be cool to support
+ _moduleLogger.warn("Unsuported type %s" % h.get_name())
+ elif h.get_name() == 'stored':
+ # On protocols where the user's contacts are stored, this contact list
+ # contains all stored contacts regardless of subscription status.
+ ChannelClass = AllContactsListChannel
+ else:
+ raise TypeError("Unknown list type : " + h.get_name())
+ return ChannelClass(connection, h)
+