use a nec Event to dispatch RIE events

This commit is contained in:
Yann Leboulanger 2010-07-30 01:30:59 +02:00
parent 59534e95e1
commit 18f03edd62
2 changed files with 59 additions and 43 deletions

View File

@ -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

View File

@ -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):