6 import util.coroutines as coroutines
11 _moduleLogger = logging.getLogger("channel.contact_list")
14 class AllContactsListChannel(
15 tp.ChannelTypeContactList,
16 tp.ChannelInterfaceGroup,
19 The group of contacts for whom you receive presence
22 def __init__(self, connection, manager, props, h):
23 tp.ChannelTypeContactList.__init__(self, connection, manager, props)
24 tp.ChannelInterfaceGroup.__init__(self)
26 self.__manager = manager
28 self.__session = connection.session
30 self._callback = coroutines.func_sink(
31 coroutines.expand_positional(
32 self._on_contacts_refreshed
35 self.__session.addressbook.updateSignalHandler.register_sink(
39 self.GroupFlagsChanged(0, 0)
41 addressbook = connection.session.addressbook
42 contacts = addressbook.get_contact_ids()
43 self._process_refresh(addressbook, set(contacts), set())
46 @gtk_toolbox.log_exception(_moduleLogger)
51 self.__session.addressbook.updateSignalHandler.unregister_sink(
56 tp.ChannelTypeContactList.Close(self)
57 self.remove_from_connection()
59 @gtk_toolbox.log_exception(_moduleLogger)
60 def _on_contacts_refreshed(self, addressbook, added, removed, changed):
61 self._process_refresh(addressbook, added, removed)
63 def _process_refresh(self, addressbook, added, removed):
64 _moduleLogger.info("Added: %r, Removed: %r" % (len(added), len(removed)))
65 connection = self._conn
67 handle.create_handle(connection, "contact", contactId, phoneNumber)
68 for contactId in added
69 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
72 handle.create_handle(connection, "contact", contactId, phoneNumber)
73 for contactId in removed
74 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
78 reason = telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
81 handlesAdded, handlesRemoved,
88 def create_contact_list_channel(connection, manager, props, h):
89 if h.get_name() == 'subscribe':
90 # The group of contacts for whom you receive presence
91 ChannelClass = AllContactsListChannel
92 elif h.get_name() == 'publish':
93 # The group of contacts who may receive your presence
94 ChannelClass = AllContactsListChannel
95 elif h.get_name() == 'hide':
96 # A group of contacts who are on the publish list but are temporarily
97 # disallowed from receiving your presence
98 # This doesn't make sense to support
99 _moduleLogger.warn("Unsuported type %s" % h.get_name())
100 elif h.get_name() == 'allow':
101 # A group of contacts who may send you messages
102 # @todo Allow-List would be cool to support
103 _moduleLogger.warn("Unsuported type %s" % h.get_name())
104 elif h.get_name() == 'deny':
105 # A group of contacts who may not send you messages
106 # @todo Deny-List would be cool to support
107 _moduleLogger.warn("Unsuported type %s" % h.get_name())
108 elif h.get_name() == 'stored':
109 # On protocols where the user's contacts are stored, this contact list
110 # contains all stored contacts regardless of subscription status.
111 ChannelClass = AllContactsListChannel
113 raise TypeError("Unknown list type : " + h.get_name())
114 return ChannelClass(connection, manager, props, h)