From 25a764a6568c1c6d4af9cd065a3abe0191a97660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Tue, 8 Aug 2017 16:44:03 +0200 Subject: [PATCH] Port logging incoming messages to new DB API --- gajim/session.py | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/gajim/session.py b/gajim/session.py index 714514fda..eaff1ab04 100644 --- a/gajim/session.py +++ b/gajim/session.py @@ -21,6 +21,8 @@ ## along with Gajim. If not, see . ## +import nbxmpp + from common import helpers from common import events @@ -31,6 +33,7 @@ from common import contacts from common import ged from common.connection_handlers_events import ChatstateReceivedEvent, \ InformationEvent +from common.logger import KindConstant import message_control @@ -86,21 +89,13 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): if not obj.msgtxt and obj.chatstate is None: return - log_type = 'chat_msg' + log_type = KindConstant.CHAT_MSG_RECV + if obj.forwarded and obj.sent: + log_type = KindConstant.CHAT_MSG_SENT else: - log_type = 'single_msg' - end = '_recv' - if obj.forwarded and obj.sent: - end = '_sent' - log_type += end - - if self.is_loggable() and obj.msgtxt: - if obj.xhtml and gajim.config.get('log_xhtml_messages'): - msg_to_log = obj.xhtml - else: - msg_to_log = obj.msgtxt - obj.msg_log_id = gajim.logger.write(log_type, obj.fjid, - msg_to_log, tim=obj.timestamp, subject=obj.subject, additional_data=obj.additional_data) + log_type = KindConstant.SINGLE_MSG_RECV + if obj.forwarded and obj.sent: + log_type = KindConstant.SINGLE_MSG_SENT treat_as = gajim.config.get('treat_incoming_messages') if treat_as: @@ -111,6 +106,22 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): pm = True obj.mtype = 'pm' + if self.is_loggable() and obj.msgtxt: + if obj.xhtml and gajim.config.get('log_xhtml_messages'): + msg_to_log = obj.xhtml + else: + msg_to_log = obj.msgtxt + + jid = obj.fjid + if not pm: + jid = obj.jid + + obj.msg_log_id = gajim.logger.insert_into_logs( + jid, obj.timestamp, log_type, + message=msg_to_log, + subject=obj.subject, + additional_data=obj.additional_data) + # Handle chat states if contact and (not obj.forwarded or not obj.sent): if self.control and self.control.type_id == \