48
48
def create_group():
49
49
if self._handle.group is None:
50
connection.msn_client.address_book.add_group(self._handle.name)
50
name = self._handle.name.encode("utf-8")
51
connection.msn_client.address_book.add_group(name)
53
54
def AddMembers(self, contacts, message):
56
57
for contact_handle_id in contacts:
57
58
contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
59
logger.info("Adding contact %r to pending group %r" %
60
(contact_handle, self._handle))
60
logger.info("Adding contact %s to pending group %s" %
61
(unicode(contact_handle), unicode(self._handle)))
61
62
if contact_handle_id in self.__pending_remove:
62
63
self.__pending_remove.remove(contact_handle_id)
67
68
for contact_handle_id in contacts:
68
69
contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
70
logger.info("Adding contact %r to group %r" %
71
(contact_handle, self._handle))
71
logger.info("Adding contact %s to group %s" %
72
(unicode(contact_handle), unicode(self._handle)))
72
73
contact = contact_handle.contact
73
74
group = self._handle.group
74
75
if contact is not None and contact.is_member(papyon.Membership.FORWARD):
82
83
for contact_handle_id in contacts:
83
84
contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
85
logger.info("Adding contact %r to pending group %r" %
86
(contact_handle, self._handle))
86
logger.info("Adding contact %s to pending group %s" %
87
(unicode(contact_handle), unicode(self._handle)))
87
88
if contact_handle_id in self.__pending_add:
88
89
self.__pending_add.remove(contact_handle_id)
93
94
for contact_handle_id in contacts:
94
95
contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
96
logger.info("Removing contact %r from pending group %r" %
97
(contact_handle, self._handle))
97
logger.info("Removing contact %s from pending group %s" %
98
(unicode(contact_handle), unicode(self._handle)))
98
99
contact = contact_handle.contact
99
100
group = self._handle.group
100
101
if contact is not None and contact.is_member(papyon.Membership.FORWARD):
109
110
ab.delete_group(group)
111
112
def _filter_contact(self, contact):
112
for group in contact.groups:
113
if group.name == self._handle.name:
114
return (True, False, False)
113
if contact.is_member(papyon.Membership.FORWARD):
114
for group in contact.groups:
115
if group.name.decode("utf-8") == self._handle.name:
116
return (True, False, False)
115
117
return (False, False, False)
117
119
def on_addressbook_group_added(self, group):
118
if group.name == self._handle.name:
120
if group.name.decode("utf-8") == self._handle.name:
119
121
self.AddMembers(self.__pending_add, None)
120
122
self.__pending_add = []
121
123
self.RemoveMembers(self.__pending_remove, None)
122
124
self.__pending_remove = []
124
126
def on_addressbook_group_deleted(self, group):
125
if group.name == self._handle.name:
127
if group.name.decode("utf-8") == self._handle.name:
127
129
self._conn.remove_channel(self)
129
131
def on_addressbook_group_contact_added(self, group, contact):
130
if group.name == self._handle.name:
132
group_name = group.name.decode("utf-8")
133
if group_name == self._handle.name:
131
134
handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
132
135
contact.account, contact.network_id)
137
140
self.MembersChanged('', added, (), (), (), 0,
138
141
telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
140
logger.debug("Contact %s added to group %s" % (handle.name,
143
logger.debug("Contact %s added to group %s" %
144
(handle.name, group_name))
143
146
def on_addressbook_group_contact_deleted(self, group, contact):
144
if group.name == self._handle.name:
147
group_name = group.name.decode("utf-8")
148
if group_name == self._handle.name:
145
149
handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
146
150
contact.account, contact.network_id)
151
155
self.MembersChanged('', (), removed, (), (), 0,
152
156
telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
154
logger.debug("Contact %s removed from group %s" % (handle.name,
158
logger.debug("Contact %s removed from group %s" %
159
(handle.name, group_name))