From 81566df8a1f988c5820309ec2865b8ced895fc8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 30 Jul 2017 22:53:32 +0200 Subject: [PATCH] Fix some regressions with MAM - On single messages use the bare JID for DB querys - Add more debug logging - Some light refactoring --- gajim/common/connection_handlers_events.py | 8 ++++++-- gajim/common/logger.py | 13 ++++++++----- gajim/common/message_archiving.py | 11 +++++------ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/gajim/common/connection_handlers_events.py b/gajim/common/connection_handlers_events.py index 61fc6ae06..9098098db 100644 --- a/gajim/common/connection_handlers_events.py +++ b/gajim/common/connection_handlers_events.py @@ -1113,8 +1113,12 @@ class MamDecryptedMessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): base_network_events = [] def generate(self): - is_pm = gajim.logger.jid_is_room_jid(self.with_.getStripped()) - if is_pm is None: + if not self.msgtxt: + # For example Chatstates, Receipts, Chatmarkers + log.debug('Received MAM message without text') + return False + self.is_pm = gajim.logger.jid_is_room_jid(self.with_.getStripped()) + if self.is_pm is None: # we don't know this JID, we need to disco it. server = self.with_.getDomain() if server not in self.conn.mam_awaiting_disco_result: diff --git a/gajim/common/logger.py b/gajim/common/logger.py index a3f01d96e..d35fd6083 100644 --- a/gajim/common/logger.py +++ b/gajim/common/logger.py @@ -1139,15 +1139,15 @@ class Logger: (account_jid_id,)) self._timeout_commit() - def save_if_not_exists(self, with_, direction, tim, msg='', is_pm=False, additional_data=None): + def save_if_not_exists(self, with_, direction, tim, msg, is_pm=False, additional_data=None): if additional_data is None: additional_data = {} - if not msg: - return if is_pm: + with_ = str(with_) type_ = 'gc_msg' else: + with_ = with_.getStripped() if direction == 'from': type_ = 'chat_msg_recv' elif direction == 'to': @@ -1156,19 +1156,22 @@ class Logger: start_time = tim - 300 # 5 minutes arrount given time end_time = tim + 300 # 5 minutes arrount given time + log.debug('start: %s, end: %s, jid: %s, message: %s', + start_time, end_time, with_, msg) + sql = ''' SELECT * FROM logs NATURAL JOIN jids WHERE jid = ? AND message = ? AND time BETWEEN ? AND ? ''' - result = self.con.execute(sql, (str(with_), msg, start_time, end_time)).fetchone() + result = self.con.execute(sql, (with_, msg, start_time, end_time)).fetchone() if result: log.debug('Log already in DB, ignoring it') return log.debug('New log received from server archives, storing it') - self.write(type_, str(with_), message=msg, tim=tim, + self.write(type_, with_, message=msg, tim=tim, additional_data=additional_data, mam_query=True) def _nec_gc_message_received(self, obj): diff --git a/gajim/common/message_archiving.py b/gajim/common/message_archiving.py index edf325ea6..4795c8b6b 100644 --- a/gajim/common/message_archiving.py +++ b/gajim/common/message_archiving.py @@ -83,17 +83,16 @@ class ConnectionArchive313: # it's a groupchat for with_, direction, tim, msg_txt in \ self.mam_awaiting_disco_result[obj.jid]: - gajim.logger.get_jid_id(with_, 'ROOM') + gajim.logger.get_jid_id(with_.getStripped(), 'ROOM') gajim.logger.save_if_not_exists(with_, direction, tim, - msg=msg_txt, is_pm=True) + msg_txt, is_pm=True) del self.mam_awaiting_disco_result[obj.jid] return # it's not a groupchat for with_, direction, tim, msg_txt in \ self.mam_awaiting_disco_result[obj.jid]: - gajim.logger.get_jid_id(with_) - gajim.logger.save_if_not_exists(with_, direction, tim, - msg=msg_txt) + gajim.logger.get_jid_id(with_.getStripped()) + gajim.logger.save_if_not_exists(with_, direction, tim, msg_txt) del self.mam_awaiting_disco_result[obj.jid] def _nec_result_finished(self, obj): @@ -123,7 +122,7 @@ class ConnectionArchive313: if obj.conn.name != self.name: return gajim.logger.save_if_not_exists(obj.with_, obj.direction, obj.timestamp, - msg=obj.msgtxt, additional_data=obj.additional_data) + obj.msgtxt, is_pm=obj.is_pm, additional_data=obj.additional_data) def get_query_id(self): self.mam_query_id = self.connection.getAnID()