changeset ed394b2ccf73 in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=ed394b2ccf73
description: use a nec Event to dispatch RIE events
diffstat:
src/common/connection_handlers.py | 94 ++++++++++++++++++++++----------------
src/gui_interface.py | 8 ++-
2 files changed, 59 insertions(+), 43 deletions(-)
diffs (149 lines):
diff -r b0b37486595d -r ed394b2ccf73 src/common/connection_handlers.py
--- a/src/common/connection_handlers.py Thu Jul 29 12:50:54 2010 +0200
+++ b/src/common/connection_handlers.py Fri Jul 30 01:30:59 2010 +0200
@@ -1277,44 +1277,9 @@
"""
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 @@
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 @@
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 -r b0b37486595d -r ed394b2ccf73 src/gui_interface.py
--- a/src/gui_interface.py Thu Jul 29 12:50:54 2010 +0200
+++ b/src/gui_interface.py Fri Jul 30 01:30:59 2010 +0200
@@ -1835,9 +1835,10 @@
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 @@
'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 @@
'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):
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits