Commit cc032163 authored by Yann Leboulanger's avatar Yann Leboulanger

more usage of NEC to handle messages

parent 2c1f20b7
......@@ -1603,6 +1603,8 @@ class ChatControl(ChatControlBase):
self._nec_vcard_received)
gajim.ged.register_event_handler('failed-decrypt', ged.GUI1,
self._nec_failed_decrypt)
gajim.ged.register_event_handler('chatstate-received', ged.GUI1,
self._nec_chatstate_received)
# PluginSystem: adding GUI extension point for this ChatControl
# instance object
......@@ -2593,6 +2595,8 @@ class ChatControl(ChatControlBase):
self._nec_vcard_received)
gajim.ged.remove_event_handler('failed-decrypt', ged.GUI1,
self._nec_failed_decrypt)
gajim.ged.remove_event_handler('chatstate-received', ged.GUI1,
self._nec_chatstate_received)
self.send_chatstate('gone', self.contact)
self.contact.chatstate = None
......@@ -2661,7 +2665,7 @@ class ChatControl(ChatControlBase):
return
on_yes(self)
def handle_incoming_chatstate(self):
def _nec_chatstate_received(self, obj):
"""
Handle incoming chatstate that jid SENT TO us
"""
......
......@@ -1329,18 +1329,15 @@ ConnectionJingle, ConnectionIBBytestream):
if obj.mtype == 'error':
self.dispatch_error_message(obj.stanza, obj.msgtxt,
obj.session, obj.fjid, obj.timestamp)
return True
elif obj.mtype == 'groupchat':
gajim.nec.push_incoming_event(GcMessageReceivedEvent(None,
conn=self, msg_obj=obj))
return True
elif obj.invite_tag is not None:
gajim.nec.push_incoming_event(GcInvitationReceivedEvent(None,
conn=self, msg_obj=obj))
else:
if isinstance(obj.session, gajim.default_session_type):
obj.session.received(obj.fjid, obj.msgtxt, obj.timestamp,
obj.encrypted, obj.stanza)
else:
obj.session.received(obj.stanza)
return True
# process and dispatch an error message
def dispatch_error_message(self, msg, msgtxt, session, frm, tim):
......
......@@ -65,6 +65,34 @@ class HelperEvent:
tim = helpers.datetime_tuple(tag)
self.timestamp = localtime(timegm(tim))
def get_chatstate(self):
"""
Extract chatstate from a <message/> stanza
Requires self.stanza and self.msgtxt
"""
self.composing_xep = None
self.chatstate = None
# chatstates - look for chatstate tags in a message if not delayed
delayed = self.stanza.getTag('x', namespace=xmpp.NS_DELAY) is not None
if not delayed:
self.composing_xep = False
children = self.stanza.getChildren()
for child in children:
if child.getNamespace() == 'http://jabber.org/protocol/chatstates':
self.chatstate = child.getName()
self.composing_xep = 'XEP-0085'
break
# No XEP-0085 support, fallback to XEP-0022
if not self.chatstate:
chatstate_child = self.stanza.getTag('x',
namespace=xmpp.NS_EVENT)
if chatstate_child:
self.chatstate = 'active'
self.composing_xep = 'XEP-0022'
if not self.msgtxt and chatstate_child.getTag('composing'):
self.chatstate = 'composing'
class HttpAuthReceivedEvent(nec.NetworkIncomingEvent):
name = 'http-auth-received'
base_network_events = []
......@@ -1021,7 +1049,7 @@ class GcInvitationReceivedEvent(nec.NetworkIncomingEvent):
return True
class DecryptedMessageReceivedEvent(nec.NetworkIncomingEvent):
class DecryptedMessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
name = 'decrypted-message-received'
base_network_events = []
......@@ -1044,6 +1072,43 @@ class DecryptedMessageReceivedEvent(nec.NetworkIncomingEvent):
namespace=xmpp.NS_RECEIPTS)
self.receipt_received_tag = self.stanza.getTag('received',
namespace=xmpp.NS_RECEIPTS)
self.subject = self.stanza.getSubject()
self.displaymarking = None
self.seclabel = self.stanza.getTag('securitylabel',
namespace=xmpp.NS_SECLABEL)
if self.seclabel:
self.displaymarking = self.seclabel.getTag('displaymarking')
self.form_node = self.stanza.getTag('x', namespace=xmpp.NS_DATA)
if gajim.config.get('ignore_incoming_xhtml'):
self.xhtml = None
else:
self.xhtml = self.stanza.getXHTML()
# XEP-0172 User Nickname
self.user_nick = self.stanza.getTagData('nick') or ''
treat_as = gajim.config.get('treat_incoming_messages')
if treat_as:
self.mtype = treat_as
self.get_chatstate()
return True
class ChatstateReceivedEvent(nec.NetworkIncomingEvent):
name = 'chatstate-received'
base_network_events = []
def generate(self):
self.stanza = self.msg_obj.stanza
self.jid = self.msg_obj.jid
self.fjid = self.msg_obj.fjid
self.resource = self.msg_obj.resource
self.composing_xep = self.msg_obj.composing_xep
self.chatstate = self.msg_obj.chatstate
return True
class GcMessageReceivedEvent(nec.NetworkIncomingEvent):
......
This diff is collapsed.
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