Fix some regressions with MAM

- On single messages use the bare JID for DB querys
- Add more debug logging
- Some light refactoring
This commit is contained in:
Philipp Hörist 2017-07-30 22:53:32 +02:00
parent c1decf682b
commit 81566df8a1
3 changed files with 19 additions and 13 deletions

View File

@ -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:

View File

@ -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):

View File

@ -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()