6 import util.go_utils as gobject_utils
7 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._conn_ref = weakref.ref(connection)
25 self._addessbook = connection.addressbook
28 class AllContactsListChannel(AbstractListChannel):
30 The group of contacts for whom you receive presence
33 def __init__(self, connection, h):
34 AbstractListChannel.__init__(self, connection, h)
35 self._addressbook.updateSignalHandle.register_sink(
36 self._on_contacts_refreshed
40 @coroutines.expand_positional
42 def _on_contacts_refreshed(self, addressbook, added, removed, changed):
43 connection = self._conn_ref()
45 handle.create_handle(connection, "contact", contactId)
46 for contactId in added
49 handle.create_handle(connection, "contact", contactId)
50 for contactId in removed
54 reason = telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
57 handlesAdded, handlesRemoved,
64 def create_contact_list_channel(connection, h):
65 if h.get_name() == 'subscribe':
66 # The group of contacts for whom you receive presence
67 ChannelClass = AllContactsListChannel
68 elif h.get_name() == 'publish':
69 # The group of contacts who may receive your presence
70 ChannelClass = AllContactsListChannel
71 elif h.get_name() == 'hide':
72 # A group of contacts who are on the publish list but are temporarily
73 # disallowed from receiving your presence
74 # This doesn't make sense to support
75 _moduleLogger.warn("Unsuported type %s" % h.get_name())
76 elif h.get_name() == 'allow':
77 # A group of contacts who may send you messages
78 # @todo This would be cool to support
79 _moduleLogger.warn("Unsuported type %s" % h.get_name())
80 elif h.get_name() == 'deny':
81 # A group of contacts who may not send you messages
82 # @todo This would be cool to support
83 _moduleLogger.warn("Unsuported type %s" % h.get_name())
84 elif h.get_name() == 'stored':
85 # On protocols where the user's contacts are stored, this contact list
86 # contains all stored contacts regardless of subscription status.
87 ChannelClass = AllContactsListChannel
89 raise TypeError("Unknown list type : " + h.get_name())
90 return ChannelClass(connection, h)