From 18f03edd62b65372fe878259c1d787776199d247 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Fri, 30 Jul 2010 01:30:59 +0200 Subject: [PATCH] use a nec Event to dispatch RIE events --- src/common/connection_handlers.py | 94 ++++++++++++++++++------------- src/gui_interface.py | 8 ++- 2 files changed, 59 insertions(+), 43 deletions(-) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 055fcc4fe..68e6220e1 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1277,44 +1277,9 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle): """ XEP-0144 Roster Item Echange """ - exchange_items_list = {} - jid_from = helpers.get_full_jid_from_iq(msg) - items_list = msg.getTag('x').getChildren() - if not items_list: - return - action = items_list[0].getAttr('action') - if action == None: - action = 'add' - for item in msg.getTag('x', - namespace=common.xmpp.NS_ROSTERX).getChildren(): - try: - jid = helpers.parse_jid(item.getAttr('jid')) - except common.helpers.InvalidFormat: - log.warn('Invalid JID: %s, ignoring it' % item.getAttr('jid')) - continue - name = item.getAttr('name') - contact = gajim.contacts.get_contact(self.name, jid) - groups = [] - same_groups = True - for group in item.getTags('group'): - groups.append(group.getData()) - # check that all suggested groups are in the groups we have for this - # contact - if not contact or group not in contact.groups: - same_groups = False - if contact: - # check that all groups we have for this contact are in the - # suggested groups - for group in contact.groups: - if group not in groups: - same_groups = False - if contact.sub in ('both', 'to') and same_groups: - continue - exchange_items_list[jid] = [] - exchange_items_list[jid].append(name) - exchange_items_list[jid].append(groups) - if exchange_items_list: - self.dispatch('ROSTERX', (action, exchange_items_list, jid_from)) + log.debug('rosterItemExchangeCB') + gajim.nec.push_incoming_event(RosterItemExchangeEvent(None, + conn=self, iq_obj=msg)) raise common.xmpp.NodeProcessed def _messageCB(self, con, msg): @@ -2357,8 +2322,8 @@ class HelperEvent: who = self.conn.groupchat_jids[self.id_] del self.conn.groupchat_jids[self.id_] else: - who = helpers.get_full_jid_from_iq(self.iq_obj) - self.jid, self.resource = gajim.get_room_and_nick_from_fjid(who) + self.fjid = helpers.get_full_jid_from_iq(self.iq_obj) + self.jid, self.resource = gajim.get_room_and_nick_from_fjid(self.fjid) def get_id(self): self.id_ = self.iq_obj.getID() @@ -2560,3 +2525,52 @@ class GMailQueryReceivedEvent(nec.NetworkIncomingEvent): log.debug(('You have %s new gmail e-mails on %s.') % (self.newmsgs, self.jid)) return True + +class RosterItemExchangeEvent(nec.NetworkIncomingEvent, HelperEvent): + name = 'roster-item-exchange-received' + base_network_events = [] + + def generate(self): + if not self.conn: + self.conn = self.base_event.conn + if not self.iq_obj: + self.iq_obj = self.base_event.xmpp_iq + + self.get_jid_resource() + self.exchange_items_list = {} + items_list = msg.getTag('x').getChildren() + if not items_list: + return + self.action = items_list[0].getAttr('action') + if self.action is None: + self.action = 'add' + for item in msg.getTag('x', namespace=common.xmpp.NS_ROSTERX).\ + getChildren(): + try: + jid = helpers.parse_jid(item.getAttr('jid')) + except common.helpers.InvalidFormat: + log.warn('Invalid JID: %s, ignoring it' % item.getAttr('jid')) + continue + name = item.getAttr('name') + contact = gajim.contacts.get_contact(self.conn.name, jid) + groups = [] + same_groups = True + for group in item.getTags('group'): + groups.append(group.getData()) + # check that all suggested groups are in the groups we have for this + # contact + if not contact or group not in contact.groups: + same_groups = False + if contact: + # check that all groups we have for this contact are in the + # suggested groups + for group in contact.groups: + if group not in groups: + same_groups = False + if contact.sub in ('both', 'to') and same_groups: + continue + self.exchange_items_list[jid] = [] + self.exchange_items_list[jid].append(name) + self.exchange_items_list[jid].append(groups) + if exchange_items_list: + return True \ No newline at end of file diff --git a/src/gui_interface.py b/src/gui_interface.py index 92d5c0815..ac6d4cd3f 100644 --- a/src/gui_interface.py +++ b/src/gui_interface.py @@ -1835,9 +1835,10 @@ class Interface: if 'pep_services' in self.instances[account]: self.instances[account]['pep_services'].config(data[0], data[1]) - def handle_event_roster_item_exchange(self, account, data): + def handle_event_roster_item_exchange(self, obj): # data = (action in [add, delete, modify], exchange_list, jid_from) - dialogs.RosterItemExchangeWindow(account, data[0], data[1], data[2]) + dialogs.RosterItemExchangeWindow(obj.conn.name, obj.action, + obj.exchange_items_list, obj.fjid) def handle_event_unique_room_id_supported(self, account, data): """ @@ -2126,7 +2127,6 @@ class Interface: 'SEARCH_FORM': [self.handle_event_search_form], 'SEARCH_RESULT': [self.handle_event_search_result], 'RESOURCE_CONFLICT': [self.handle_event_resource_conflict], - 'ROSTERX': [self.handle_event_roster_item_exchange], 'PEP_CONFIG': [self.handle_event_pep_config], 'UNIQUE_ROOM_ID_UNSUPPORTED': \ [self.handle_event_unique_room_id_unsupported], @@ -2150,6 +2150,8 @@ class Interface: 'gmail-notify': [self.handle_event_gmail_notify], 'http-auth-received': [self.handle_event_http_auth], 'last-result-received': [self.handle_event_last_status_time], + 'roster-item-exchange-received': \ + [self.handle_event_roster_item_exchange], } def register_core_handlers(self):