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, manager, props, h):
21 self._manager = manager
25 # HACK Older python-telepathy way
26 telepathy.server.ChannelTypeContactList.__init__(self, connection, h)
28 # HACK Newer python-telepathy way
29 telepathy.server.ChannelTypeContactList.__init__(self, connection, manager, props)
30 telepathy.server.ChannelInterfaceGroup.__init__(self)
32 self._session = connection.session
35 class AllContactsListChannel(AbstractListChannel):
37 The group of contacts for whom you receive presence
40 def __init__(self, connection, manager, props, h):
41 AbstractListChannel.__init__(self, connection, manager, props, h)
43 self._callback = coroutines.func_sink(
44 coroutines.expand_positional(
45 self._on_contacts_refreshed
48 self._session.addressbook.updateSignalHandler.register_sink(
52 self.GroupFlagsChanged(0, 0)
54 addressbook = connection.session.addressbook
55 contacts = addressbook.get_contacts()
56 self._process_refresh(addressbook, contacts, [])
58 @gtk_toolbox.log_exception(_moduleLogger)
63 self._session.addressbook.updateSignalHandler.unregister_sink(
68 telepathy.server.ChannelTypeContactList.Close(self)
69 if self._manager.channel_exists(self._props):
70 # HACK Older python-telepathy requires doing this manually
71 self._manager.remove_channel(self)
72 self.remove_from_connection()
75 @gtk_toolbox.log_exception(_moduleLogger)
76 def _on_contacts_refreshed(self, addressbook, added, removed, changed):
77 self._process_refresh(addressbook, added, removed)
79 def _process_refresh(self, addressbook, added, removed):
80 connection = self._conn
82 handle.create_handle(connection, "contact", contactId, phoneNumber)
83 for contactId in added
84 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
87 handle.create_handle(connection, "contact", contactId, phoneNumber)
88 for contactId in removed
89 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
93 reason = telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
96 handlesAdded, handlesRemoved,
103 def create_contact_list_channel(connection, manager, props, h):
104 if h.get_name() == 'subscribe':
105 # The group of contacts for whom you receive presence
106 ChannelClass = AllContactsListChannel
107 elif h.get_name() == 'publish':
108 # The group of contacts who may receive your presence
109 ChannelClass = AllContactsListChannel
110 elif h.get_name() == 'hide':
111 # A group of contacts who are on the publish list but are temporarily
112 # disallowed from receiving your presence
113 # This doesn't make sense to support
114 _moduleLogger.warn("Unsuported type %s" % h.get_name())
115 elif h.get_name() == 'allow':
116 # A group of contacts who may send you messages
117 # @todo Allow-List would be cool to support
118 _moduleLogger.warn("Unsuported type %s" % h.get_name())
119 elif h.get_name() == 'deny':
120 # A group of contacts who may not send you messages
121 # @todo Deny-List would be cool to support
122 _moduleLogger.warn("Unsuported type %s" % h.get_name())
123 elif h.get_name() == 'stored':
124 # On protocols where the user's contacts are stored, this contact list
125 # contains all stored contacts regardless of subscription status.
126 ChannelClass = AllContactsListChannel
128 raise TypeError("Unknown list type : " + h.get_name())
129 return ChannelClass(connection, manager, props, h)