Move message error handler into message module
This commit is contained in:
parent
c0fb645309
commit
cdb37828e4
|
@ -32,12 +32,10 @@ import nbxmpp
|
||||||
from gajim.common import app
|
from gajim.common import app
|
||||||
from gajim.common import helpers
|
from gajim.common import helpers
|
||||||
from gajim.common import jingle_xtls
|
from gajim.common import jingle_xtls
|
||||||
from gajim.common.const import KindConstant
|
|
||||||
from gajim.common.jingle import ConnectionJingle
|
from gajim.common.jingle import ConnectionJingle
|
||||||
from gajim.common.protocol.bytestream import ConnectionSocks5Bytestream
|
from gajim.common.protocol.bytestream import ConnectionSocks5Bytestream
|
||||||
from gajim.common.protocol.bytestream import ConnectionIBBytestream
|
from gajim.common.protocol.bytestream import ConnectionIBBytestream
|
||||||
from gajim.common.connection_handlers_events import StreamReceivedEvent
|
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 PresenceReceivedEvent
|
||||||
from gajim.common.connection_handlers_events import StreamConflictReceivedEvent
|
from gajim.common.connection_handlers_events import StreamConflictReceivedEvent
|
||||||
from gajim.common.connection_handlers_events import NotificationEvent
|
from gajim.common.connection_handlers_events import NotificationEvent
|
||||||
|
@ -54,28 +52,6 @@ class ConnectionHandlersBase:
|
||||||
# IDs of sent messages (https://trac.gajim.org/ticket/8222)
|
# IDs of sent messages (https://trac.gajim.org/ticket/8222)
|
||||||
self.sent_message_ids = []
|
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):
|
def get_sessions(self, jid):
|
||||||
"""
|
"""
|
||||||
Get all sessions for the given full 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.misc import parse_xhtml
|
||||||
from gajim.common.modules.util import is_self_message
|
from gajim.common.modules.util import is_self_message
|
||||||
from gajim.common.modules.util import is_muc_pm
|
from gajim.common.modules.util import is_muc_pm
|
||||||
|
from gajim.common.connection_handlers_events import MessageErrorEvent
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger('gajim.c.m.message')
|
log = logging.getLogger('gajim.c.m.message')
|
||||||
|
@ -250,9 +251,19 @@ class Message:
|
||||||
if event.gc_control:
|
if event.gc_control:
|
||||||
event.gc_control.print_conversation(event.msgtxt)
|
event.gc_control.print_conversation(event.msgtxt)
|
||||||
else:
|
else:
|
||||||
self._con.dispatch_error_message(
|
self._log_error_message(event)
|
||||||
event.stanza, event.msgtxt,
|
error_msg = event.stanza.getErrorMsg() or event.msgtxt
|
||||||
event.session, event.fjid, timestamp)
|
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
|
return
|
||||||
|
|
||||||
if groupchat:
|
if groupchat:
|
||||||
|
@ -274,6 +285,16 @@ class Message:
|
||||||
DecryptedMessageReceivedEvent(
|
DecryptedMessageReceivedEvent(
|
||||||
None, **vars(event)))
|
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):
|
def _log_muc_message(self, event):
|
||||||
if event.mtype == 'error':
|
if event.mtype == 'error':
|
||||||
return
|
return
|
||||||
|
|
|
@ -32,12 +32,14 @@ from gajim.common import connection_handlers
|
||||||
from gajim.common.i18n import _
|
from gajim.common.i18n import _
|
||||||
from gajim.common.helpers import AdditionalDataDict
|
from gajim.common.helpers import AdditionalDataDict
|
||||||
from gajim.common.nec import NetworkIncomingEvent, NetworkEvent
|
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.user_nickname import parse_nickname
|
||||||
from gajim.common.modules.misc import parse_eme
|
from gajim.common.modules.misc import parse_eme
|
||||||
from gajim.common.modules.misc import parse_correction
|
from gajim.common.modules.misc import parse_correction
|
||||||
from gajim.common.modules.misc import parse_attention
|
from gajim.common.modules.misc import parse_attention
|
||||||
from gajim.common.modules.misc import parse_oob
|
from gajim.common.modules.misc import parse_oob
|
||||||
from gajim.common.modules.misc import parse_xhtml
|
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')
|
log = logging.getLogger('gajim.c.z.connection_handlers_zeroconf')
|
||||||
|
@ -163,10 +165,31 @@ class ConnectionHandlersZeroconf(ConnectionSocks5BytestreamZeroconf,
|
||||||
if event.mtype == 'error':
|
if event.mtype == 'error':
|
||||||
if not event.msgtxt:
|
if not event.msgtxt:
|
||||||
event.msgtxt = _('message')
|
event.msgtxt = _('message')
|
||||||
self.dispatch_error_message(
|
self._log_error_message(event)
|
||||||
event.stanza, event.msgtxt,
|
error_msg = event.stanza.getErrorMsg() or event.msgtxt
|
||||||
event.session, event.fjid, event.timestamp)
|
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
|
return
|
||||||
|
|
||||||
app.nec.push_incoming_event(
|
app.nec.push_incoming_event(
|
||||||
DecryptedMessageReceivedEvent(None, **vars(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)
|
||||||
|
|
Loading…
Reference in New Issue