Commit 5cb8def2 authored by Yann Leboulanger's avatar Yann Leboulanger

use NEC to handle metacontacts events

parent 92ef8bfe
......@@ -651,31 +651,8 @@ class ConnectionVcard:
if not self.connection:
return
if iq_obj.getType() == 'result':
# Metacontact tags
# http://www.xmpp.org/extensions/xep-0209.html
meta_list = {}
query = iq_obj.getTag('query')
storage = query.getTag('storage')
metas = storage.getTags('meta')
for meta in metas:
try:
jid = helpers.parse_jid(meta.getAttr('jid'))
except common.helpers.InvalidFormat:
continue
tag = meta.getAttr('tag')
data = {'jid': jid}
order = meta.getAttr('order')
try:
order = int(order)
except Exception:
order = 0
if order is not None:
data['order'] = order
if tag in meta_list:
meta_list[tag].append(data)
else:
meta_list[tag] = [data]
self.dispatch('METACONTACTS', meta_list)
gajim.nec.push_incoming_event(MetacontactsReceivedEvent(None,
conn=self, stanza=iq_obj))
else:
if iq_obj.getErrorCode() not in ('403', '406', '404'):
self.private_storage_supported = False
......
......@@ -1522,4 +1522,35 @@ class VcardReceivedEvent(nec.NetworkIncomingEvent):
class PEPConfigReceivedEvent(nec.NetworkIncomingEvent):
name = 'pep-config-received'
base_network_events = []
\ No newline at end of file
base_network_events = []
class MetacontactsReceivedEvent(nec.NetworkIncomingEvent):
name = 'metacontacts-received'
base_network_events = []
def generate(self):
# Metacontact tags
# http://www.xmpp.org/extensions/xep-0209.html
self.meta_list = {}
query = self.stanza.getTag('query')
storage = self.stanza.getTag('storage')
metas = self.stanza.getTags('meta')
for meta in metas:
try:
jid = helpers.parse_jid(meta.getAttr('jid'))
except common.helpers.InvalidFormat:
continue
tag = meta.getAttr('tag')
data = {'jid': jid}
order = meta.getAttr('order')
try:
order = int(order)
except Exception:
order = 0
if order is not None:
data['order'] = order
if tag in self.meta_list:
self.meta_list[tag].append(data)
else:
self.meta_list[tag] = [data]
return True
......@@ -1056,9 +1056,8 @@ class Interface:
gajim.config.set_per('accounts', account, 'last_archiving_time',
time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()))
def handle_event_metacontacts(self, account, tags_list):
gajim.contacts.define_metacontacts(account, tags_list)
self.roster.redraw_metacontacts(account)
def handle_event_metacontacts(self, obj):
gajim.contacts.define_metacontacts(obj.conn.name, obj.meta_list)
def handle_atom_entry(self, obj):
AtomWindow.newAtomEntry(obj.atom_entry)
......@@ -1420,7 +1419,6 @@ class Interface:
'FILE_REQUEST_ERROR': [self.handle_event_file_request_error],
'FILE_SEND_ERROR': [self.handle_event_file_send_error],
'SIGNED_IN': [self.handle_event_signed_in],
'METACONTACTS': [self.handle_event_metacontacts],
'FAILED_DECRYPT': [self.handle_event_failed_decrypt],
'ZC_NAME_CONFLICT': [self.handle_event_zc_name_conflict],
'PASSWORD_REQUIRED': [self.handle_event_password_required],
......@@ -1447,6 +1445,7 @@ class Interface:
'last-result-received': [self.handle_event_last_status_time],
'message-not-sent': [self.handle_event_msgnotsent],
'message-sent': [self.handle_event_msgsent],
'metacontacts-received': [self.handle_event_metacontacts],
'muc-admin-received': [self.handle_event_gc_affiliation],
'muc-owner-received': [self.handle_event_gc_config],
'our-show': [self.handle_event_status],
......
......@@ -2514,6 +2514,9 @@ class RosterWindow:
contact.status = obj.subject
self.draw_contact(obj.room_jid, obj.conn.name)
def _nec_metacontacts_received(self, obj):
self.redraw_metacontacts(obj.conn.name)
################################################################################
### Menu and GUI callbacks
### FIXME: order callbacks in itself...
......@@ -6266,3 +6269,5 @@ class RosterWindow:
self._nec_vcard_received)
gajim.ged.register_event_handler('gc-subject-received', ged.GUI1,
self._nec_gc_subject_received)
gajim.ged.register_event_handler('metacontacts-received', ged.GUI2,
self._nec_metacontacts_received)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment