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._session = connection.session
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._session.addressbook.updateSignalHandler.register_sink(
36 self._on_contacts_refreshed
38 self.GroupFlagsChanged(0, 0)
41 @coroutines.expand_positional
43 def _on_contacts_refreshed(self, addressbook, added, removed, changed):
45 @todo This currently filters out people not yet added to the contact
46 list. Something needs to be done about those
47 @todo This currently does not handle people with multiple phone
48 numbers, yay that'll be annoying to resolve
50 connection = self._conn_ref()
52 handle.create_handle(connection, "contact", contactId)
53 for contactId in added
57 handle.create_handle(connection, "contact", contactId)
58 for contactId in removed
63 reason = telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
66 handlesAdded, handlesRemoved,
73 def create_contact_list_channel(connection, h):
74 if h.get_name() == 'subscribe':
75 # The group of contacts for whom you receive presence
76 ChannelClass = AllContactsListChannel
77 elif h.get_name() == 'publish':
78 # The group of contacts who may receive your presence
79 ChannelClass = AllContactsListChannel
80 elif h.get_name() == 'hide':
81 # A group of contacts who are on the publish list but are temporarily
82 # disallowed from receiving your presence
83 # This doesn't make sense to support
84 _moduleLogger.warn("Unsuported type %s" % h.get_name())
85 elif h.get_name() == 'allow':
86 # A group of contacts who may send you messages
87 # @todo Allow-List would be cool to support
88 _moduleLogger.warn("Unsuported type %s" % h.get_name())
89 elif h.get_name() == 'deny':
90 # A group of contacts who may not send you messages
91 # @todo Deny-List would be cool to support
92 _moduleLogger.warn("Unsuported type %s" % h.get_name())
93 elif h.get_name() == 'stored':
94 # On protocols where the user's contacts are stored, this contact list
95 # contains all stored contacts regardless of subscription status.
96 ChannelClass = AllContactsListChannel
98 raise TypeError("Unknown list type : " + h.get_name())
99 return ChannelClass(connection, h)