Commit cdb37828 authored by Philipp Hörist's avatar Philipp Hörist

Move message error handler into message module

parent c0fb6453
......@@ -32,12 +32,10 @@ import nbxmpp
from gajim.common import app
from gajim.common import helpers
from gajim.common import jingle_xtls
from gajim.common.const import KindConstant
from gajim.common.jingle import ConnectionJingle
from gajim.common.protocol.bytestream import ConnectionSocks5Bytestream
from gajim.common.protocol.bytestream import ConnectionIBBytestream
from gajim.common.connection_handlers_events import StreamReceivedEvent
from gajim.common.connection_handlers_events import MessageErrorEvent
from gajim.common.connection_handlers_events import PresenceReceivedEvent
from gajim.common.connection_handlers_events import StreamConflictReceivedEvent
from gajim.common.connection_handlers_events import NotificationEvent
......@@ -54,28 +52,6 @@ class ConnectionHandlersBase:
# IDs of sent messages (https://trac.gajim.org/ticket/8222)
self.sent_message_ids = []
# process and dispatch an error message
def dispatch_error_message(self, msg, msgtxt, session, frm, tim):
error_msg = msg.getErrorMsg()
if not error_msg:
error_msg = msgtxt
msgtxt = None
subject = msg.getSubject()
if session.is_loggable():
app.logger.insert_into_logs(self.name,
nbxmpp.JID(frm).getStripped(),
tim,
KindConstant.ERROR,
message=error_msg,
subject=subject)
app.nec.push_incoming_event(MessageErrorEvent(None, conn=self,
fjid=frm, error_code=msg.getErrorCode(), error_msg=error_msg,
msg=msgtxt, time_=tim, session=session, stanza=msg))
def get_sessions(self, jid):
"""
Get all sessions for the given full jid
......
......@@ -38,6 +38,7 @@ from gajim.common.modules.misc import parse_oob
from gajim.common.modules.misc import parse_xhtml
from gajim.common.modules.util import is_self_message
from gajim.common.modules.util import is_muc_pm
from gajim.common.connection_handlers_events import MessageErrorEvent
log = logging.getLogger('gajim.c.m.message')
......@@ -250,9 +251,19 @@ class Message:
if event.gc_control:
event.gc_control.print_conversation(event.msgtxt)
else:
self._con.dispatch_error_message(
event.stanza, event.msgtxt,
event.session, event.fjid, timestamp)
self._log_error_message(event)
error_msg = event.stanza.getErrorMsg() or event.msgtxt
msgtxt = None if error_msg == event.msgtxt else event.msgtxt
app.nec.push_incoming_event(
MessageErrorEvent(None,
conn=self._con,
fjid=event.fjid,
error_code=event.stanza.getErrorCode(),
error_msg=error_msg,
msg=msgtxt,
time_=event.timestamp,
session=event.session,
stanza=event.stanza))
return
if groupchat:
......@@ -274,6 +285,16 @@ class Message:
DecryptedMessageReceivedEvent(
None, **vars(event)))
def _log_error_message(self, event):
error_msg = event.stanza.getErrorMsg() or event.msgtxt
if app.config.should_log(self._account, event.jid):
app.logger.insert_into_logs(self._account,
event.jid,
event.timestamp,
KindConstant.ERROR,
message=error_msg,
subject=event.subject)
def _log_muc_message(self, event):
if event.mtype == 'error':
return
......
......@@ -32,12 +32,14 @@ from gajim.common import connection_handlers
from gajim.common.i18n import _
from gajim.common.helpers import AdditionalDataDict
from gajim.common.nec import NetworkIncomingEvent, NetworkEvent
from gajim.common.const import KindConstant
from gajim.common.modules.user_nickname import parse_nickname
from gajim.common.modules.misc import parse_eme
from gajim.common.modules.misc import parse_correction
from gajim.common.modules.misc import parse_attention
from gajim.common.modules.misc import parse_oob
from gajim.common.modules.misc import parse_xhtml
from gajim.common.connection_handlers_events import MessageErrorEvent
log = logging.getLogger('gajim.c.z.connection_handlers_zeroconf')
......@@ -163,10 +165,31 @@ class ConnectionHandlersZeroconf(ConnectionSocks5BytestreamZeroconf,
if event.mtype == 'error':
if not event.msgtxt:
event.msgtxt = _('message')
self.dispatch_error_message(
event.stanza, event.msgtxt,
event.session, event.fjid, event.timestamp)
self._log_error_message(event)
error_msg = event.stanza.getErrorMsg() or event.msgtxt
msgtxt = None if error_msg == event.msgtxt else event.msgtxt
app.nec.push_incoming_event(
MessageErrorEvent(None,
conn=self,
fjid=event.fjid,
error_code=event.stanza.getErrorCode(),
error_msg=error_msg,
msg=msgtxt,
time_=event.timestamp,
session=event.session,
stanza=event.stanza))
return
app.nec.push_incoming_event(
DecryptedMessageReceivedEvent(None, **vars(event)))
def _log_error_message(self, event):
error_msg = event.stanza.getErrorMsg() or event.msgtxt
if app.config.should_log(self.name, event.jid):
app.logger.insert_into_logs(self.name,
event.jid,
event.timestamp,
KindConstant.ERROR,
message=error_msg,
subject=event.subject)
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