9 def create_contact_list_channel(connection, h):
10 if h.get_name() == 'subscribe':
11 channel_class = TheOneRingSubscribeListChannel
12 elif h.get_name() == 'publish':
13 channel_class = TheOneRingPublishListChannel
14 elif h.get_name() == 'hide':
15 logging.warn("Unsuported type %s" % h.get_name())
16 elif h.get_name() == 'allow':
17 logging.warn("Unsuported type %s" % h.get_name())
18 elif h.get_name() == 'deny':
19 logging.warn("Unsuported type %s" % h.get_name())
21 raise TypeError("Unknown list type : " + h.get_name())
22 return channel_class(connection, h)
25 class TheOneRingListChannel(
26 telepathy.server.ChannelTypeContactList,
27 telepathy.server.ChannelInterfaceGroup,
29 "Abstract Contact List channels"
31 def __init__(self, connection, h):
32 telepathy.server.ChannelTypeContactList.__init__(self, connection, h)
33 telepathy.server.ChannelInterfaceGroup.__init__(self)
35 self._conn_ref = weakref.ref(connection)
37 def GetLocalPendingMembersWithInfo(self):
41 class TheOneRingSubscribeListChannel(TheOneRingListChannel):
43 Subscribe List channel.
45 This channel contains the list of contact to whom the current used is
46 'subscribed', basically this list contains the contact for whom you are
47 supposed to receive presence notification.
50 def __init__(self, connection, h):
51 TheOneRingListChannel.__init__(self, connection, h)
52 self.GroupFlagsChanged(
53 telepathy.CHANNEL_GROUP_FLAG_CAN_ADD |
54 telepathy.CHANNEL_GROUP_FLAG_CAN_REMOVE,
58 def AddMembers(self, contacts, message):
59 addressBook = self._conn.gvoice_client
61 h = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, h)
66 account = contact.account
67 groups = list(h.pending_groups)
68 h.pending_groups = set()
69 addressBook.add_messenger_contact(account,
70 invite_message=message.encode('utf-8'),
73 def RemoveMembers(self, contacts, message):
74 addressBook = self._conn.gvoice_client
76 h = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, h)
78 addressBook.delete_contact(contact)
81 class TheOneRingPublishListChannel(TheOneRingListChannel):
83 def __init__(self, connection, h):
84 TheOneRingListChannel.__init__(self, connection, h)
85 self.GroupFlagsChanged(0, 0)
87 def AddMembers(self, contacts, message):
88 addressBook = self._conn.gvoice_client
89 for contactHandleId in contacts:
90 contactHandle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
92 contact = contactHandle.contact
93 addressBook.accept_contact_invitation(contact, False)
95 def RemoveMembers(self, contacts, message):
96 addressBook = self._conn.gvoice_client
97 for contactHandleId in contacts:
98 contactHandle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
100 contact = contactHandle.contact
102 def GetLocalPendingMembersWithInfo(self):
103 addressBook = self._conn.gvoice_client
105 for contact in addressBook.contacts:
106 h = handle.create_handle(self._conn_ref(), 'contact',
107 contact.account, contact.network_id)
109 telepathy.CHANNEL_GROUP_CHANGE_REASON_INVITED,
110 contact.attributes.get('invite_message', '')))