Move MUC message logging into message module
This commit is contained in:
parent
4631f50372
commit
c0fb645309
|
@ -570,9 +570,7 @@ class Connection(CommonConnection, ConnectionHandlers):
|
||||||
# END __init__
|
# END __init__
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
ConnectionHandlers.cleanup(self)
|
|
||||||
modules.unregister(self)
|
modules.unregister(self)
|
||||||
|
|
||||||
app.ged.remove_event_handler('message-outgoing', ged.OUT_CORE,
|
app.ged.remove_event_handler('message-outgoing', ged.OUT_CORE,
|
||||||
self._nec_message_outgoing)
|
self._nec_message_outgoing)
|
||||||
app.ged.remove_event_handler('gc-message-outgoing', ged.OUT_CORE,
|
app.ged.remove_event_handler('gc-message-outgoing', ged.OUT_CORE,
|
||||||
|
|
|
@ -30,10 +30,8 @@ import operator
|
||||||
import nbxmpp
|
import nbxmpp
|
||||||
|
|
||||||
from gajim.common import app
|
from gajim.common import app
|
||||||
from gajim.common import ged
|
|
||||||
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.caps_cache import muc_caps_cache
|
|
||||||
from gajim.common.const import KindConstant
|
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
|
||||||
|
@ -56,44 +54,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 = []
|
||||||
|
|
||||||
app.ged.register_event_handler('gc-message-received', ged.CORE,
|
|
||||||
self._nec_gc_message_received)
|
|
||||||
|
|
||||||
def cleanup(self):
|
|
||||||
app.ged.remove_event_handler('gc-message-received', ged.CORE,
|
|
||||||
self._nec_gc_message_received)
|
|
||||||
|
|
||||||
def _check_for_mam_compliance(self, room_jid, stanza_id):
|
|
||||||
namespace = muc_caps_cache.get_mam_namespace(room_jid)
|
|
||||||
if stanza_id is None and namespace == nbxmpp.NS_MAM_2:
|
|
||||||
log.warning('%s announces mam:2 without stanza-id', room_jid)
|
|
||||||
|
|
||||||
def _nec_gc_message_received(self, obj):
|
|
||||||
if obj.conn.name != self.name:
|
|
||||||
return
|
|
||||||
|
|
||||||
if obj.stanza.getType() == 'error':
|
|
||||||
return
|
|
||||||
|
|
||||||
self._check_for_mam_compliance(obj.jid, obj.stanza_id)
|
|
||||||
|
|
||||||
if (app.config.should_log(obj.conn.name, obj.jid) and
|
|
||||||
obj.msgtxt and obj.nick):
|
|
||||||
# if not obj.nick, it means message comes from room itself
|
|
||||||
# usually it hold description and can be send at each connection
|
|
||||||
# so don't store it in logs
|
|
||||||
app.logger.insert_into_logs(self.name,
|
|
||||||
obj.jid,
|
|
||||||
obj.timestamp,
|
|
||||||
KindConstant.GC_MSG,
|
|
||||||
message=obj.msgtxt,
|
|
||||||
contact_name=obj.nick,
|
|
||||||
additional_data=obj.additional_data,
|
|
||||||
stanza_id=obj.stanza_id)
|
|
||||||
app.logger.set_room_last_message_time(obj.room_jid, obj.timestamp)
|
|
||||||
self.get_module('MAM').save_archive_id(
|
|
||||||
obj.room_jid, obj.stanza_id, obj.timestamp)
|
|
||||||
|
|
||||||
# process and dispatch an error message
|
# process and dispatch an error message
|
||||||
def dispatch_error_message(self, msg, msgtxt, session, frm, tim):
|
def dispatch_error_message(self, msg, msgtxt, session, frm, tim):
|
||||||
error_msg = msg.getErrorMsg()
|
error_msg = msg.getErrorMsg()
|
||||||
|
@ -260,9 +220,6 @@ class ConnectionHandlers(ConnectionSocks5Bytestream,
|
||||||
app.nec.register_incoming_event(StreamConflictReceivedEvent)
|
app.nec.register_incoming_event(StreamConflictReceivedEvent)
|
||||||
app.nec.register_incoming_event(NotificationEvent)
|
app.nec.register_incoming_event(NotificationEvent)
|
||||||
|
|
||||||
def cleanup(self):
|
|
||||||
ConnectionHandlersBase.cleanup(self)
|
|
||||||
|
|
||||||
def _PubkeyGetCB(self, con, iq_obj):
|
def _PubkeyGetCB(self, con, iq_obj):
|
||||||
log.info('PubkeyGetCB')
|
log.info('PubkeyGetCB')
|
||||||
jid_from = helpers.get_full_jid_from_iq(iq_obj)
|
jid_from = helpers.get_full_jid_from_iq(iq_obj)
|
||||||
|
|
|
@ -21,10 +21,12 @@ 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 caps_cache
|
||||||
from gajim.common.i18n import _
|
from gajim.common.i18n import _
|
||||||
from gajim.common.nec import NetworkIncomingEvent
|
from gajim.common.nec import NetworkIncomingEvent
|
||||||
from gajim.common.nec import NetworkEvent
|
from gajim.common.nec import NetworkEvent
|
||||||
from gajim.common.helpers import AdditionalDataDict
|
from gajim.common.helpers import AdditionalDataDict
|
||||||
|
from gajim.common.const import KindConstant
|
||||||
from gajim.common.modules.security_labels import parse_securitylabel
|
from gajim.common.modules.security_labels import parse_securitylabel
|
||||||
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_delay
|
from gajim.common.modules.misc import parse_delay
|
||||||
|
@ -264,12 +266,43 @@ class Message:
|
||||||
|
|
||||||
app.nec.push_incoming_event(NetworkEvent('gc-message-received',
|
app.nec.push_incoming_event(NetworkEvent('gc-message-received',
|
||||||
**vars(event)))
|
**vars(event)))
|
||||||
|
# TODO: Some plugins modify msgtxt in the GUI event
|
||||||
|
self._log_muc_message(event)
|
||||||
return
|
return
|
||||||
|
|
||||||
app.nec.push_incoming_event(
|
app.nec.push_incoming_event(
|
||||||
DecryptedMessageReceivedEvent(
|
DecryptedMessageReceivedEvent(
|
||||||
None, **vars(event)))
|
None, **vars(event)))
|
||||||
|
|
||||||
|
def _log_muc_message(self, event):
|
||||||
|
if event.mtype == 'error':
|
||||||
|
return
|
||||||
|
|
||||||
|
self._check_for_mam_compliance(event.room_jid, event.stanza_id)
|
||||||
|
|
||||||
|
if (app.config.should_log(self._account, event.jid) and
|
||||||
|
event.msgtxt and event.nick):
|
||||||
|
# if not event.nick, it means message comes from room itself
|
||||||
|
# usually it hold description and can be send at each connection
|
||||||
|
# so don't store it in logs
|
||||||
|
app.logger.insert_into_logs(self._account,
|
||||||
|
event.jid,
|
||||||
|
event.timestamp,
|
||||||
|
KindConstant.GC_MSG,
|
||||||
|
message=event.msgtxt,
|
||||||
|
contact_name=event.nick,
|
||||||
|
additional_data=event.additional_data,
|
||||||
|
stanza_id=event.stanza_id)
|
||||||
|
app.logger.set_room_last_message_time(event.room_jid, event.timestamp)
|
||||||
|
self._con.get_module('MAM').save_archive_id(
|
||||||
|
event.room_jid, event.stanza_id, event.timestamp)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _check_for_mam_compliance(room_jid, stanza_id):
|
||||||
|
namespace = caps_cache.muc_caps_cache.get_mam_namespace(room_jid)
|
||||||
|
if stanza_id is None and namespace == nbxmpp.NS_MAM_2:
|
||||||
|
log.warning('%s announces mam:2 without stanza-id', room_jid)
|
||||||
|
|
||||||
def _get_unique_id(self, stanza, _forwarded, _sent, self_message, _muc_pm):
|
def _get_unique_id(self, stanza, _forwarded, _sent, self_message, _muc_pm):
|
||||||
if stanza.getType() == 'groupchat':
|
if stanza.getType() == 'groupchat':
|
||||||
# TODO: Disco the MUC check if 'urn:xmpp:mam:2' is announced
|
# TODO: Disco the MUC check if 'urn:xmpp:mam:2' is announced
|
||||||
|
|
Loading…
Reference in New Issue