use a nec Event to dispatch RIE events
This commit is contained in:
parent
59534e95e1
commit
18f03edd62
|
@ -1277,44 +1277,9 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
|
||||||
"""
|
"""
|
||||||
XEP-0144 Roster Item Echange
|
XEP-0144 Roster Item Echange
|
||||||
"""
|
"""
|
||||||
exchange_items_list = {}
|
log.debug('rosterItemExchangeCB')
|
||||||
jid_from = helpers.get_full_jid_from_iq(msg)
|
gajim.nec.push_incoming_event(RosterItemExchangeEvent(None,
|
||||||
items_list = msg.getTag('x').getChildren()
|
conn=self, iq_obj=msg))
|
||||||
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))
|
|
||||||
raise common.xmpp.NodeProcessed
|
raise common.xmpp.NodeProcessed
|
||||||
|
|
||||||
def _messageCB(self, con, msg):
|
def _messageCB(self, con, msg):
|
||||||
|
@ -2357,8 +2322,8 @@ class HelperEvent:
|
||||||
who = self.conn.groupchat_jids[self.id_]
|
who = self.conn.groupchat_jids[self.id_]
|
||||||
del self.conn.groupchat_jids[self.id_]
|
del self.conn.groupchat_jids[self.id_]
|
||||||
else:
|
else:
|
||||||
who = helpers.get_full_jid_from_iq(self.iq_obj)
|
self.fjid = helpers.get_full_jid_from_iq(self.iq_obj)
|
||||||
self.jid, self.resource = gajim.get_room_and_nick_from_fjid(who)
|
self.jid, self.resource = gajim.get_room_and_nick_from_fjid(self.fjid)
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
self.id_ = self.iq_obj.getID()
|
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,
|
log.debug(('You have %s new gmail e-mails on %s.') % (self.newmsgs,
|
||||||
self.jid))
|
self.jid))
|
||||||
return True
|
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
|
|
@ -1835,9 +1835,10 @@ class Interface:
|
||||||
if 'pep_services' in self.instances[account]:
|
if 'pep_services' in self.instances[account]:
|
||||||
self.instances[account]['pep_services'].config(data[0], data[1])
|
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)
|
# 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):
|
def handle_event_unique_room_id_supported(self, account, data):
|
||||||
"""
|
"""
|
||||||
|
@ -2126,7 +2127,6 @@ class Interface:
|
||||||
'SEARCH_FORM': [self.handle_event_search_form],
|
'SEARCH_FORM': [self.handle_event_search_form],
|
||||||
'SEARCH_RESULT': [self.handle_event_search_result],
|
'SEARCH_RESULT': [self.handle_event_search_result],
|
||||||
'RESOURCE_CONFLICT': [self.handle_event_resource_conflict],
|
'RESOURCE_CONFLICT': [self.handle_event_resource_conflict],
|
||||||
'ROSTERX': [self.handle_event_roster_item_exchange],
|
|
||||||
'PEP_CONFIG': [self.handle_event_pep_config],
|
'PEP_CONFIG': [self.handle_event_pep_config],
|
||||||
'UNIQUE_ROOM_ID_UNSUPPORTED': \
|
'UNIQUE_ROOM_ID_UNSUPPORTED': \
|
||||||
[self.handle_event_unique_room_id_unsupported],
|
[self.handle_event_unique_room_id_unsupported],
|
||||||
|
@ -2150,6 +2150,8 @@ class Interface:
|
||||||
'gmail-notify': [self.handle_event_gmail_notify],
|
'gmail-notify': [self.handle_event_gmail_notify],
|
||||||
'http-auth-received': [self.handle_event_http_auth],
|
'http-auth-received': [self.handle_event_http_auth],
|
||||||
'last-result-received': [self.handle_event_last_status_time],
|
'last-result-received': [self.handle_event_last_status_time],
|
||||||
|
'roster-item-exchange-received': \
|
||||||
|
[self.handle_event_roster_item_exchange],
|
||||||
}
|
}
|
||||||
|
|
||||||
def register_core_handlers(self):
|
def register_core_handlers(self):
|
||||||
|
|
Loading…
Reference in New Issue