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