use NEC to handle caps events
This commit is contained in:
parent
1ed5de8f44
commit
d94a85f5a2
|
@ -2108,7 +2108,6 @@ ConnectionJingle, ConnectionIBBytestream):
|
||||||
# that defines handlers
|
# that defines handlers
|
||||||
con.RegisterHandler('message', self._messageCB)
|
con.RegisterHandler('message', self._messageCB)
|
||||||
con.RegisterHandler('presence', self._presenceCB)
|
con.RegisterHandler('presence', self._presenceCB)
|
||||||
con.RegisterHandler('presence', self._capsPresenceCB)
|
|
||||||
# We use makefirst so that this handler is called before _messageCB, and
|
# We use makefirst so that this handler is called before _messageCB, and
|
||||||
# can prevent calling it when it's not needed.
|
# can prevent calling it when it's not needed.
|
||||||
# We also don't check for namespace, else it cannot stop _messageCB to
|
# We also don't check for namespace, else it cannot stop _messageCB to
|
||||||
|
|
|
@ -1334,3 +1334,42 @@ class PingReplyEvent(nec.NetworkIncomingEvent):
|
||||||
class PingErrorEvent(nec.NetworkIncomingEvent):
|
class PingErrorEvent(nec.NetworkIncomingEvent):
|
||||||
name = 'ping-error'
|
name = 'ping-error'
|
||||||
base_network_events = []
|
base_network_events = []
|
||||||
|
|
||||||
|
class CapsPresenceReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||||
|
name = 'caps-presence-received'
|
||||||
|
base_network_events = ['raw-pres-received']
|
||||||
|
|
||||||
|
def _extract_caps_from_presence(self):
|
||||||
|
caps_tag = self.stanza.getTag('c', namespace=xmpp.NS_CAPS)
|
||||||
|
if caps_tag:
|
||||||
|
self.hash_method = caps_tag['hash']
|
||||||
|
self.node = caps_tag['node']
|
||||||
|
self.caps_hash = caps_tag['ver']
|
||||||
|
else:
|
||||||
|
self.hash_method = self.node = self.caps_hash = None
|
||||||
|
|
||||||
|
def generate(self):
|
||||||
|
self.conn = self.base_event.conn
|
||||||
|
self.stanza = self.base_event.stanza
|
||||||
|
try:
|
||||||
|
self.get_jid_resource()
|
||||||
|
except Exception:
|
||||||
|
return
|
||||||
|
self._extract_caps_from_presence()
|
||||||
|
return True
|
||||||
|
|
||||||
|
class CapsDiscoReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||||
|
name = 'caps-disco-received'
|
||||||
|
base_network_events = []
|
||||||
|
|
||||||
|
class CapsReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||||
|
name = 'caps-received'
|
||||||
|
base_network_events = ['caps-presence-received', 'caps-disco-received']
|
||||||
|
|
||||||
|
def generate(self):
|
||||||
|
self.conn = self.base_event.conn
|
||||||
|
self.fjid = self.base_event.fjid
|
||||||
|
self.jid = self.base_event.jid
|
||||||
|
self.resource = self.base_event.resource
|
||||||
|
self.client_caps = self.base_event.client_caps
|
||||||
|
return True
|
||||||
|
|
|
@ -25,9 +25,11 @@ Module containing the network portion of XEP-115 (Entity Capabilities)
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger('gajim.c.p.caps')
|
log = logging.getLogger('gajim.c.p.caps')
|
||||||
|
|
||||||
from common.xmpp import NS_CAPS
|
|
||||||
from common import gajim
|
from common import gajim
|
||||||
|
from common import ged
|
||||||
from common import helpers
|
from common import helpers
|
||||||
|
from common.connection_handlers_events import CapsPresenceReceivedEvent, \
|
||||||
|
CapsDiscoReceivedEvent, CapsReceivedEvent
|
||||||
|
|
||||||
|
|
||||||
class ConnectionCaps(object):
|
class ConnectionCaps(object):
|
||||||
|
@ -37,40 +39,27 @@ class ConnectionCaps(object):
|
||||||
self._dispatch_event = dispatch_event
|
self._dispatch_event = dispatch_event
|
||||||
self._capscache = capscache
|
self._capscache = capscache
|
||||||
self._create_suitable_client_caps = client_caps_factory
|
self._create_suitable_client_caps = client_caps_factory
|
||||||
|
gajim.nec.register_incoming_event(CapsPresenceReceivedEvent)
|
||||||
|
gajim.nec.register_incoming_event(CapsReceivedEvent)
|
||||||
|
gajim.ged.register_event_handler('caps-presence-received', ged.GUI1,
|
||||||
|
self._nec_caps_presence_received)
|
||||||
|
|
||||||
def caps_change_account_name(self, new_name):
|
def caps_change_account_name(self, new_name):
|
||||||
self._account = new_name
|
self._account = new_name
|
||||||
|
|
||||||
def _capsPresenceCB(self, con, presence):
|
def _nec_caps_presence_received(self, obj):
|
||||||
"""
|
obj.client_caps = self._create_suitable_client_caps(obj.node,
|
||||||
XMMPPY callback method to handle retrieved caps info
|
obj.caps_hash, obj.hash_method)
|
||||||
"""
|
self._capscache.query_client_of_jid_if_unknown(self, obj.fjid,
|
||||||
try:
|
obj.client_caps)
|
||||||
jid = helpers.get_full_jid_from_iq(presence)
|
self._update_client_caps_of_contact(obj)
|
||||||
except:
|
|
||||||
log.info("Ignoring invalid JID in caps presenceCB")
|
|
||||||
return
|
|
||||||
|
|
||||||
client_caps = self._extract_client_caps_from_presence(presence)
|
def _update_client_caps_of_contact(self, obj):
|
||||||
self._capscache.query_client_of_jid_if_unknown(self, jid, client_caps)
|
contact = self._get_contact_or_gc_contact_for_jid(obj.fjid)
|
||||||
self._update_client_caps_of_contact(jid, client_caps)
|
|
||||||
|
|
||||||
self._dispatch_event('CAPS_RECEIVED', (jid,))
|
|
||||||
|
|
||||||
def _extract_client_caps_from_presence(self, presence):
|
|
||||||
caps_tag = presence.getTag('c', namespace=NS_CAPS)
|
|
||||||
if caps_tag:
|
|
||||||
hash_method, node, caps_hash = caps_tag['hash'], caps_tag['node'], caps_tag['ver']
|
|
||||||
else:
|
|
||||||
hash_method = node = caps_hash = None
|
|
||||||
return self._create_suitable_client_caps(node, caps_hash, hash_method)
|
|
||||||
|
|
||||||
def _update_client_caps_of_contact(self, jid, client_caps):
|
|
||||||
contact = self._get_contact_or_gc_contact_for_jid(jid)
|
|
||||||
if contact:
|
if contact:
|
||||||
contact.client_caps = client_caps
|
contact.client_caps = obj.client_caps
|
||||||
else:
|
else:
|
||||||
log.info("Received Caps from unknown contact %s" % jid)
|
log.info('Received Caps from unknown contact %s' % obj.fjid)
|
||||||
|
|
||||||
def _get_contact_or_gc_contact_for_jid(self, jid):
|
def _get_contact_or_gc_contact_for_jid(self, jid):
|
||||||
contact = gajim.contacts.get_contact_from_full_jid(self._account, jid)
|
contact = gajim.contacts.get_contact_from_full_jid(self._account, jid)
|
||||||
|
@ -109,4 +98,7 @@ class ConnectionCaps(object):
|
||||||
log.info("Computed and retrieved caps hash differ." +
|
log.info("Computed and retrieved caps hash differ." +
|
||||||
"Ignoring caps of contact %s" % contact.get_full_jid())
|
"Ignoring caps of contact %s" % contact.get_full_jid())
|
||||||
|
|
||||||
self._dispatch_event('CAPS_RECEIVED', (jid,))
|
j, r = gajim.get_room_and_nick_from_fjid(jid)
|
||||||
|
gajim.nec.push_incoming_event(CapsDiscoReceivedEvent(None,
|
||||||
|
conn=self, fjid=jid, jid=j, resource=r,
|
||||||
|
client_caps=contact.client_caps))
|
||||||
|
|
|
@ -149,6 +149,16 @@ class PrivateChatControl(ChatControl):
|
||||||
ChatControl.__init__(self, parent_win, contact, account, session)
|
ChatControl.__init__(self, parent_win, contact, account, session)
|
||||||
self.TYPE_ID = 'pm'
|
self.TYPE_ID = 'pm'
|
||||||
|
|
||||||
|
def shutdown(self):
|
||||||
|
gajim.ged.remove_event_handler('caps-received', ged.GUI1,
|
||||||
|
self._nec_caps_received)
|
||||||
|
|
||||||
|
def _nec_caps_received(self, obj):
|
||||||
|
if obj.conn.name != self.account or \
|
||||||
|
obj.fjid != self.gc_contact.get_full_jid():
|
||||||
|
return
|
||||||
|
self.update_contact()
|
||||||
|
|
||||||
def send_message(self, message, xhtml=None, process_commands=True):
|
def send_message(self, message, xhtml=None, process_commands=True):
|
||||||
"""
|
"""
|
||||||
Call this method to send the message
|
Call this method to send the message
|
||||||
|
|
|
@ -1698,13 +1698,6 @@ class Interface:
|
||||||
if ctrl:
|
if ctrl:
|
||||||
ctrl.update_pep(pep_type)
|
ctrl.update_pep(pep_type)
|
||||||
|
|
||||||
def handle_event_caps_received(self, account, data):
|
|
||||||
# ('CAPS_RECEIVED', account, (full_jid))
|
|
||||||
full_jid = data[0]
|
|
||||||
pm_ctrl = gajim.interface.msg_win_mgr.get_control(full_jid, account)
|
|
||||||
if pm_ctrl and hasattr(pm_ctrl, "update_contact"):
|
|
||||||
pm_ctrl.update_contact()
|
|
||||||
|
|
||||||
def create_core_handlers_list(self):
|
def create_core_handlers_list(self):
|
||||||
self.handlers = {
|
self.handlers = {
|
||||||
'WARNING': [self.handle_event_warning],
|
'WARNING': [self.handle_event_warning],
|
||||||
|
@ -1748,7 +1741,6 @@ class Interface:
|
||||||
[self.handle_event_insecure_ssl_connection],
|
[self.handle_event_insecure_ssl_connection],
|
||||||
'INSECURE_PASSWORD': [self.handle_event_insecure_password],
|
'INSECURE_PASSWORD': [self.handle_event_insecure_password],
|
||||||
'PEP_RECEIVED': [self.handle_event_pep_received],
|
'PEP_RECEIVED': [self.handle_event_pep_received],
|
||||||
'CAPS_RECEIVED': [self.handle_event_caps_received],
|
|
||||||
'bad-gpg-passphrase': [self.handle_event_bad_gpg_passphrase],
|
'bad-gpg-passphrase': [self.handle_event_bad_gpg_passphrase],
|
||||||
'bookmarks-received': [self.handle_event_bookmarks],
|
'bookmarks-received': [self.handle_event_bookmarks],
|
||||||
'connection-lost': [self.handle_event_connection_lost],
|
'connection-lost': [self.handle_event_connection_lost],
|
||||||
|
|
Loading…
Reference in New Issue