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
21 @bug On Maemo 5 this isn't even being created, I think
24 def __init__(self, connection, manager, props, h):
25 tp.ChannelTypeContactList.__init__(self, connection, manager, props)
26 tp.ChannelInterfaceGroup.__init__(self)
28 self.__manager = manager
30 self.__session = connection.session
32 self._callback = coroutines.func_sink(
33 coroutines.expand_positional(
34 self._on_contacts_refreshed
37 self.__session.addressbook.updateSignalHandler.register_sink(
41 self.GroupFlagsChanged(0, 0)
43 addressbook = connection.session.addressbook
44 contacts = addressbook.get_contact_ids()
45 self._process_refresh(addressbook, set(contacts), set())
48 @gtk_toolbox.log_exception(_moduleLogger)
53 self.__session.addressbook.updateSignalHandler.unregister_sink(
58 tp.ChannelTypeContactList.Close(self)
59 self.remove_from_connection()
61 @gtk_toolbox.log_exception(_moduleLogger)
62 def _on_contacts_refreshed(self, addressbook, added, removed, changed):
63 self._process_refresh(addressbook, added, removed)
65 def _process_refresh(self, addressbook, added, removed):
66 _moduleLogger.info("Added: %r, Removed: %r" % (len(added), len(removed)))
67 connection = self._conn
69 handle.create_handle(connection, "contact", contactId, phoneNumber)
70 for contactId in added
71 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
74 handle.create_handle(connection, "contact", contactId, phoneNumber)
75 for contactId in removed
76 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
80 reason = telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
83 handlesAdded, handlesRemoved,
90 def create_contact_list_channel(connection, manager, props, h):
91 if h.get_name() == 'subscribe':
92 # The group of contacts for whom you receive presence
93 ChannelClass = AllContactsListChannel
94 elif h.get_name() == 'publish':
95 # The group of contacts who may receive your presence
96 ChannelClass = AllContactsListChannel
97 elif h.get_name() == 'hide':
98 # A group of contacts who are on the publish list but are temporarily
99 # disallowed from receiving your presence
100 # This doesn't make sense to support
101 _moduleLogger.warn("Unsuported type %s" % h.get_name())
102 elif h.get_name() == 'allow':
103 # A group of contacts who may send you messages
104 # @todo Allow-List would be cool to support
105 _moduleLogger.warn("Unsuported type %s" % h.get_name())
106 elif h.get_name() == 'deny':
107 # A group of contacts who may not send you messages
108 # @todo Deny-List would be cool to support
109 _moduleLogger.warn("Unsuported type %s" % h.get_name())
110 elif h.get_name() == 'stored':
111 # On protocols where the user's contacts are stored, this contact list
112 # contains all stored contacts regardless of subscription status.
113 ChannelClass = AllContactsListChannel
115 raise TypeError("Unknown list type : " + h.get_name())
116 return ChannelClass(connection, manager, props, h)