5 import util.go_utils as gobject_utils
6 import util.coroutines as coroutines
10 _moduleLogger = logging.getLogger("channel.contact_list")
13 class AbstractListChannel(
14 telepathy.server.ChannelTypeContactList,
15 telepathy.server.ChannelInterfaceGroup,
17 "Abstract Contact List channels"
19 def __init__(self, connection, h):
20 telepathy.server.ChannelTypeContactList.__init__(self, connection, h)
21 telepathy.server.ChannelInterfaceGroup.__init__(self)
23 self._session = connection.session
26 class AllContactsListChannel(AbstractListChannel):
28 The group of contacts for whom you receive presence
31 def __init__(self, connection, h):
32 AbstractListChannel.__init__(self, connection, h)
33 self._session.addressbook.updateSignalHandler.register_sink(
34 self._on_contacts_refreshed
36 self.GroupFlagsChanged(0, 0)
39 @coroutines.expand_positional
41 def _on_contacts_refreshed(self, addressbook, added, removed, changed):
43 @todo This currently filters out people not yet added to the contact
44 list. Something needs to be done about those
45 @todo This currently does not handle people with multiple phone
46 numbers, yay that'll be annoying to resolve
48 connection = self._conn
50 handle.create_handle(connection, "contact", contactId)
51 for contactId in added
55 handle.create_handle(connection, "contact", contactId)
56 for contactId in removed
61 reason = telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
64 handlesAdded, handlesRemoved,
71 def create_contact_list_channel(connection, h):
72 if h.get_name() == 'subscribe':
73 # The group of contacts for whom you receive presence
74 ChannelClass = AllContactsListChannel
75 elif h.get_name() == 'publish':
76 # The group of contacts who may receive your presence
77 ChannelClass = AllContactsListChannel
78 elif h.get_name() == 'hide':
79 # A group of contacts who are on the publish list but are temporarily
80 # disallowed from receiving your presence
81 # This doesn't make sense to support
82 _moduleLogger.warn("Unsuported type %s" % h.get_name())
83 elif h.get_name() == 'allow':
84 # A group of contacts who may send you messages
85 # @todo Allow-List would be cool to support
86 _moduleLogger.warn("Unsuported type %s" % h.get_name())
87 elif h.get_name() == 'deny':
88 # A group of contacts who may not send you messages
89 # @todo Deny-List would be cool to support
90 _moduleLogger.warn("Unsuported type %s" % h.get_name())
91 elif h.get_name() == 'stored':
92 # On protocols where the user's contacts are stored, this contact list
93 # contains all stored contacts regardless of subscription status.
94 ChannelClass = AllContactsListChannel
96 raise TypeError("Unknown list type : " + h.get_name())
97 return ChannelClass(connection, h)