use NEC to handle PEP / ATOM messages
This commit is contained in:
parent
3fea030706
commit
352bda2ef5
|
@ -1597,6 +1597,9 @@ class ChatControl(ChatControlBase):
|
|||
self._video_button.set_tooltip_text(
|
||||
'%s\n%s' % (tooltip_text, _('Requires python-farsight.')))
|
||||
|
||||
gajim.ged.register_event_handler('pep-received', ged.GUI1,
|
||||
self._nec_pep_received)
|
||||
|
||||
# PluginSystem: adding GUI extension point for this ChatControl
|
||||
# instance object
|
||||
gajim.plugin_manager.gui_extension_point('chat_control', self)
|
||||
|
@ -1670,6 +1673,19 @@ class ChatControl(ChatControlBase):
|
|||
else:
|
||||
img.hide()
|
||||
|
||||
def _nec_pep_received(self, obj):
|
||||
if obj.conn.name != self.account:
|
||||
return
|
||||
if obj.jid != self.contact.jid:
|
||||
return
|
||||
|
||||
if obj.pep_type == 'nickname':
|
||||
self.update_ui()
|
||||
self.parent_win.redraw_tab(self)
|
||||
self.parent_win.show_title()
|
||||
else:
|
||||
self.update_pep(obj.pep_type)
|
||||
|
||||
def _update_jingle(self, jingle_type):
|
||||
if jingle_type not in ('audio', 'video'):
|
||||
return
|
||||
|
@ -2567,6 +2583,9 @@ class ChatControl(ChatControlBase):
|
|||
# instance object
|
||||
gajim.plugin_manager.remove_gui_extension_point('chat_control', self) # Send 'gone' chatstate
|
||||
|
||||
gajim.ged.remove_event_handler('pep-received', ged.GUI1,
|
||||
self._nec_pep_received)
|
||||
|
||||
self.send_chatstate('gone', self.contact)
|
||||
self.contact.chatstate = None
|
||||
self.contact.our_chatstate = None
|
||||
|
|
|
@ -24,6 +24,7 @@ from time import (localtime, time as time_time)
|
|||
from calendar import timegm
|
||||
import hmac
|
||||
|
||||
from common import atom
|
||||
from common import nec
|
||||
from common import helpers
|
||||
from common import gajim
|
||||
|
@ -31,6 +32,7 @@ from common import xmpp
|
|||
from common import dataforms
|
||||
from common import exceptions
|
||||
from common.logger import LOG_DB_PATH
|
||||
from common.pep import SUPPORTED_PERSONAL_USER_EVENTS
|
||||
|
||||
import logging
|
||||
log = logging.getLogger('gajim.c.connection_handlers_events')
|
||||
|
@ -1358,11 +1360,11 @@ class CapsPresenceReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|||
self._extract_caps_from_presence()
|
||||
return True
|
||||
|
||||
class CapsDiscoReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||
class CapsDiscoReceivedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'caps-disco-received'
|
||||
base_network_events = []
|
||||
|
||||
class CapsReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||
class CapsReceivedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'caps-received'
|
||||
base_network_events = ['caps-presence-received', 'caps-disco-received']
|
||||
|
||||
|
@ -1385,3 +1387,46 @@ class GPGPasswordRequiredEvent(nec.NetworkIncomingEvent):
|
|||
def generate(self):
|
||||
self.keyid = gajim.config.get_per('accounts', self.conn.name, 'keyid')
|
||||
return True
|
||||
|
||||
class PEPReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||
name = 'pep-received'
|
||||
base_network_events = []
|
||||
|
||||
def generate(self):
|
||||
if not self.stanza.getTag('event'):
|
||||
return
|
||||
if self.stanza.getTag('error'):
|
||||
log.debug('PEPReceivedEvent received error stanza. Ignoring')
|
||||
return
|
||||
|
||||
try:
|
||||
self.get_jid_resource()
|
||||
except Exception:
|
||||
return
|
||||
|
||||
self.event_tag = self.stanza.getTag('event')
|
||||
|
||||
for pep_class in SUPPORTED_PERSONAL_USER_EVENTS:
|
||||
pep = pep_class.get_tag_as_PEP(self.fjid, self.conn.name,
|
||||
self.event_tag)
|
||||
if pep:
|
||||
self.pep_type = pep.type
|
||||
return True
|
||||
|
||||
items = self.event_tag.getTag('items')
|
||||
if items:
|
||||
# for each entry in feed (there shouldn't be more than one, but to
|
||||
# be sure...
|
||||
for item in items.getTags('item'):
|
||||
entry = item.getTag('entry', namespace=xmpp.NS_ATOM)
|
||||
if entry:
|
||||
gajim.nec.push_incoming_event(AtomEntryReceived(None,
|
||||
conn=self.conn, node=entry))
|
||||
|
||||
class AtomEntryReceived(nec.NetworkIncomingEvent):
|
||||
name = 'atom-entry-received'
|
||||
base_network_events = []
|
||||
|
||||
def generate(self):
|
||||
self.atom_entry = atom.OldEntry(node=entry)
|
||||
return True
|
||||
|
|
|
@ -203,7 +203,6 @@ import logging
|
|||
log = logging.getLogger('gajim.c.pep')
|
||||
|
||||
from common import helpers
|
||||
from common import atom
|
||||
from common import xmpp
|
||||
from common import gajim
|
||||
|
||||
|
@ -492,7 +491,9 @@ class UserLocationPEP(AbstractPEP):
|
|||
|
||||
|
||||
SUPPORTED_PERSONAL_USER_EVENTS = [UserMoodPEP, UserTunePEP, UserActivityPEP,
|
||||
UserNicknamePEP, UserLocationPEP]
|
||||
UserNicknamePEP, UserLocationPEP]
|
||||
|
||||
from common.connection_handlers_events import PEPReceivedEvent
|
||||
|
||||
class ConnectionPEP(object):
|
||||
|
||||
|
@ -530,30 +531,8 @@ class ConnectionPEP(object):
|
|||
|
||||
def _pubsubEventCB(self, xmpp_dispatcher, msg):
|
||||
''' Called when we receive <message /> with pubsub event. '''
|
||||
if not msg.getTag('event'):
|
||||
return
|
||||
if msg.getTag('error'):
|
||||
log.debug('PubsubEventCB received error stanza. Ignoring')
|
||||
raise xmpp.NodeProcessed
|
||||
|
||||
jid = helpers.get_full_jid_from_iq(msg)
|
||||
event_tag = msg.getTag('event')
|
||||
|
||||
for pep_class in SUPPORTED_PERSONAL_USER_EVENTS:
|
||||
pep = pep_class.get_tag_as_PEP(jid, self._account, event_tag)
|
||||
if pep:
|
||||
self._dispatcher.dispatch('PEP_RECEIVED', (jid, pep.type))
|
||||
|
||||
items = event_tag.getTag('items')
|
||||
if items:
|
||||
for item in items.getTags('item'):
|
||||
entry = item.getTag('entry', namespace=xmpp.NS_ATOM)
|
||||
if entry:
|
||||
# for each entry in feed (there shouldn't be more than one,
|
||||
# but to be sure...
|
||||
self._dispatcher.dispatch('ATOM_ENTRY',
|
||||
(atom.OldEntry(node=entry),))
|
||||
|
||||
gajim.nec.push_incoming_event(PEPReceivedEvent(None, conn=self,
|
||||
stanza=msg))
|
||||
raise xmpp.NodeProcessed
|
||||
|
||||
def send_activity(self, activity, subactivity=None, message=None):
|
||||
|
|
|
@ -1186,9 +1186,8 @@ class Interface:
|
|||
gajim.contacts.define_metacontacts(account, tags_list)
|
||||
self.roster.redraw_metacontacts(account)
|
||||
|
||||
def handle_atom_entry(self, account, data):
|
||||
atom_entry, = data
|
||||
AtomWindow.newAtomEntry(atom_entry)
|
||||
def handle_atom_entry(self, obj):
|
||||
AtomWindow.newAtomEntry(obj.atom_entry)
|
||||
|
||||
def handle_event_failed_decrypt(self, account, data):
|
||||
jid, tim, session = data
|
||||
|
@ -1597,27 +1596,6 @@ class Interface:
|
|||
checktext2, on_response_ok=on_ok, on_response_cancel=on_cancel,
|
||||
is_modal=False)
|
||||
|
||||
def handle_event_pep_received(self, account, data):
|
||||
# ('PEP_RECEIVED', account, (jid, pep_type))
|
||||
jid = data[0]
|
||||
pep_type = data[1]
|
||||
ctrl = common.gajim.interface.msg_win_mgr.get_control(jid, account)
|
||||
|
||||
if jid == common.gajim.get_jid_from_account(account):
|
||||
self.roster.draw_account(account)
|
||||
|
||||
if pep_type == 'nickname':
|
||||
self.roster.draw_contact(jid, account)
|
||||
if ctrl:
|
||||
ctrl.update_ui()
|
||||
win = ctrl.parent_win
|
||||
win.redraw_tab(ctrl)
|
||||
win.show_title()
|
||||
else:
|
||||
self.roster.draw_pep(jid, account, pep_type)
|
||||
if ctrl:
|
||||
ctrl.update_pep(pep_type)
|
||||
|
||||
def create_core_handlers_list(self):
|
||||
self.handlers = {
|
||||
'WARNING': [self.handle_event_warning],
|
||||
|
@ -1636,7 +1614,6 @@ class Interface:
|
|||
'FILE_SEND_ERROR': [self.handle_event_file_send_error],
|
||||
'SIGNED_IN': [self.handle_event_signed_in],
|
||||
'METACONTACTS': [self.handle_event_metacontacts],
|
||||
'ATOM_ENTRY': [self.handle_atom_entry],
|
||||
'FAILED_DECRYPT': [self.handle_event_failed_decrypt],
|
||||
'PRIVACY_LISTS_RECEIVED': \
|
||||
[self.handle_event_privacy_lists_received],
|
||||
|
@ -1657,7 +1634,7 @@ class Interface:
|
|||
'INSECURE_SSL_CONNECTION': \
|
||||
[self.handle_event_insecure_ssl_connection],
|
||||
'INSECURE_PASSWORD': [self.handle_event_insecure_password],
|
||||
'PEP_RECEIVED': [self.handle_event_pep_received],
|
||||
'atom-entry-received': [self.handle_atom_entry],
|
||||
'bad-gpg-passphrase': [self.handle_event_bad_gpg_passphrase],
|
||||
'bookmarks-received': [self.handle_event_bookmarks],
|
||||
'connection-lost': [self.handle_event_connection_lost],
|
||||
|
|
|
@ -1287,7 +1287,6 @@ class RosterWindow:
|
|||
iters = self._get_contact_iter(jid, account, model=self.model)
|
||||
if not iters:
|
||||
return
|
||||
jid = self.model[iters[0]][C_JID].decode('utf-8')
|
||||
contact = gajim.contacts.get_contact(account, jid)
|
||||
if pep_type in contact.pep:
|
||||
pixbuf = contact.pep[pep_type].asPixbufIcon()
|
||||
|
@ -2493,6 +2492,15 @@ class RosterWindow:
|
|||
for jid in obj.jid_list:
|
||||
self.remove_contact(jid, obj.conn.name, backend=True)
|
||||
|
||||
def _nec_pep_received(self, obj):
|
||||
if obj.jid == common.gajim.get_jid_from_account(obj.conn.name):
|
||||
self.draw_account(obj.conn.name)
|
||||
|
||||
if obj.pep_type == 'nickname':
|
||||
self.draw_contact(obj.jid, obj.conn.name)
|
||||
else:
|
||||
self.draw_pep(obj.jid, obj.conn.name, obj.pep_type)
|
||||
|
||||
################################################################################
|
||||
### Menu and GUI callbacks
|
||||
### FIXME: order callbacks in itself...
|
||||
|
@ -6245,3 +6253,5 @@ class RosterWindow:
|
|||
self._nec_connection_type)
|
||||
gajim.ged.register_event_handler('agent-removed', ged.GUI1,
|
||||
self._nec_agent_removed)
|
||||
gajim.ged.register_event_handler('pep-received', ged.GUI1,
|
||||
self._nec_pep_received)
|
||||
|
|
Loading…
Reference in New Issue