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._callback = coroutines.func_sink(
35 coroutines.expand_positional(
36 self._on_contacts_refreshed
39 self._session.addressbook.updateSignalHandler.register_sink(
42 self.GroupFlagsChanged(0, 0)
44 addressbook = connection.session.addressbook
45 contacts = addressbook.get_contacts()
46 self._process_refresh(addressbook, contacts, [])
48 @gtk_toolbox.log_exception(_moduleLogger)
50 telepathy.server.ChannelTypeContactList.Close(self)
51 self.remove_from_connection()
52 self._session.addressbook.updateSignalHandler.unregister_sink(
57 @gtk_toolbox.log_exception(_moduleLogger)
58 def _on_contacts_refreshed(self, addressbook, added, removed, changed):
59 self._process_refresh(addressbook, added, removed)
61 def _process_refresh(self, addressbook, added, removed):
62 connection = self._conn
64 handle.create_handle(connection, "contact", contactId, phoneNumber)
65 for contactId in added
66 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
69 handle.create_handle(connection, "contact", contactId, phoneNumber)
70 for contactId in removed
71 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
75 reason = telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
78 handlesAdded, handlesRemoved,
85 def create_contact_list_channel(connection, h):
86 if h.get_name() == 'subscribe':
87 # The group of contacts for whom you receive presence
88 ChannelClass = AllContactsListChannel
89 elif h.get_name() == 'publish':
90 # The group of contacts who may receive your presence
91 ChannelClass = AllContactsListChannel
92 elif h.get_name() == 'hide':
93 # A group of contacts who are on the publish list but are temporarily
94 # disallowed from receiving your presence
95 # This doesn't make sense to support
96 _moduleLogger.warn("Unsuported type %s" % h.get_name())
97 elif h.get_name() == 'allow':
98 # A group of contacts who may send you messages
99 # @todo Allow-List would be cool to support
100 _moduleLogger.warn("Unsuported type %s" % h.get_name())
101 elif h.get_name() == 'deny':
102 # A group of contacts who may not send you messages
103 # @todo Deny-List would be cool to support
104 _moduleLogger.warn("Unsuported type %s" % h.get_name())
105 elif h.get_name() == 'stored':
106 # On protocols where the user's contacts are stored, this contact list
107 # contains all stored contacts regardless of subscription status.
108 ChannelClass = AllContactsListChannel
110 raise TypeError("Unknown list type : " + h.get_name())
111 return ChannelClass(connection, h)