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 @gtk_toolbox.log_exception(_moduleLogger)
55 def _on_contacts_refreshed(self, addressbook, added, removed, changed):
56 self._process_refresh(addressbook, added, removed)
58 def _process_refresh(self, addressbook, added, removed):
59 connection = self._conn
61 handle.create_handle(connection, "contact", contactId, phoneNumber)
62 for contactId in added
63 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
66 handle.create_handle(connection, "contact", contactId, phoneNumber)
67 for contactId in removed
68 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
72 reason = telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
75 handlesAdded, handlesRemoved,
82 def create_contact_list_channel(connection, h):
83 if h.get_name() == 'subscribe':
84 # The group of contacts for whom you receive presence
85 ChannelClass = AllContactsListChannel
86 elif h.get_name() == 'publish':
87 # The group of contacts who may receive your presence
88 ChannelClass = AllContactsListChannel
89 elif h.get_name() == 'hide':
90 # A group of contacts who are on the publish list but are temporarily
91 # disallowed from receiving your presence
92 # This doesn't make sense to support
93 _moduleLogger.warn("Unsuported type %s" % h.get_name())
94 elif h.get_name() == 'allow':
95 # A group of contacts who may send you messages
96 # @todo Allow-List would be cool to support
97 _moduleLogger.warn("Unsuported type %s" % h.get_name())
98 elif h.get_name() == 'deny':
99 # A group of contacts who may not send you messages
100 # @todo Deny-List would be cool to support
101 _moduleLogger.warn("Unsuported type %s" % h.get_name())
102 elif h.get_name() == 'stored':
103 # On protocols where the user's contacts are stored, this contact list
104 # contains all stored contacts regardless of subscription status.
105 ChannelClass = AllContactsListChannel
107 raise TypeError("Unknown list type : " + h.get_name())
108 return ChannelClass(connection, h)