5 import util.go_utils as gobject_utils
6 import util.coroutines as coroutines
11 _moduleLogger = logging.getLogger("channel.contact_list")
14 class AbstractListChannel(
15 telepathy.server.ChannelTypeContactList,
16 telepathy.server.ChannelInterfaceGroup,
18 "Abstract Contact List channels"
20 def __init__(self, connection, h):
21 telepathy.server.ChannelTypeContactList.__init__(self, connection, h)
22 telepathy.server.ChannelInterfaceGroup.__init__(self)
24 self._session = connection.session
27 class AllContactsListChannel(AbstractListChannel):
29 The group of contacts for whom you receive presence
32 def __init__(self, connection, h):
33 AbstractListChannel.__init__(self, connection, h)
34 self._session.addressbook.updateSignalHandler.register_sink(
35 self._on_contacts_refreshed
37 self.GroupFlagsChanged(0, 0)
39 addressbook = connection.session.addressbook
40 contacts = addressbook.get_contacts()
41 self._process_refresh(addressbook, contacts, [])
43 @gtk_toolbox.log_exception(_moduleLogger)
45 telepathy.server.ChannelTypeContactList.Close(self)
46 self.remove_from_connection()
47 self._session.addressbook.updateSignalHandler.unregister_sink(
48 self._on_contacts_refreshed
52 @coroutines.expand_positional
54 def _on_contacts_refreshed(self, addressbook, added, removed, changed):
55 self._process_refresh(addressbook, added, removed)
57 def _process_refresh(self, addressbook, added, removed):
58 connection = self._conn
60 handle.create_handle(connection, "contact", contactId, phoneNumber)
61 for contactId in added
62 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
65 handle.create_handle(connection, "contact", contactId, phoneNumber)
66 for contactId in removed
67 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
71 reason = telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
74 handlesAdded, handlesRemoved,
81 def create_contact_list_channel(connection, h):
82 if h.get_name() == 'subscribe':
83 # The group of contacts for whom you receive presence
84 ChannelClass = AllContactsListChannel
85 elif h.get_name() == 'publish':
86 # The group of contacts who may receive your presence
87 ChannelClass = AllContactsListChannel
88 elif h.get_name() == 'hide':
89 # A group of contacts who are on the publish list but are temporarily
90 # disallowed from receiving your presence
91 # This doesn't make sense to support
92 _moduleLogger.warn("Unsuported type %s" % h.get_name())
93 elif h.get_name() == 'allow':
94 # A group of contacts who may send you messages
95 # @todo Allow-List would be cool to support
96 _moduleLogger.warn("Unsuported type %s" % h.get_name())
97 elif h.get_name() == 'deny':
98 # A group of contacts who may not send you messages
99 # @todo Deny-List would be cool to support
100 _moduleLogger.warn("Unsuported type %s" % h.get_name())
101 elif h.get_name() == 'stored':
102 # On protocols where the user's contacts are stored, this contact list
103 # contains all stored contacts regardless of subscription status.
104 ChannelClass = AllContactsListChannel
106 raise TypeError("Unknown list type : " + h.get_name())
107 return ChannelClass(connection, h)