Philipp Hörist pushed to branch master at gajim / gajim
Commits:
922fa4f1 by Philipp Hörist at 2019-08-05T20:49:00Z
MUC: Add log message when requesting MUC history
- timestamp() makes it necessary to use timezone aware datetime objects
- - - - -
dce96b5f by Philipp Hörist at 2019-08-05T21:05:30Z
Logger: Improve log message
- - - - -
ca1b2091 by Philipp Hörist at 2019-08-05T21:58:16Z
MAM: Improve MAM efficiency
This looks at all messages incoming and saves the stanza-id if there is one.
Previously this was only done for messages of type=chat, which left out muc
invites
and captcha messages, leading to fetching these messages later again.
- - - - -
5 changed files:
- gajim/common/logger.py
- gajim/common/modules/mam.py
- gajim/common/modules/message.py
- gajim/common/modules/muc.py
- gajim/session.py
Changes:
=====================================
gajim/common/logger.py
=====================================
@@ -1463,5 +1463,5 @@ class Logger:
sql = '''UPDATE last_archive_message SET {}
WHERE jid_id = ?'''.format(args)
self._con.execute(sql, tuple(kwargs.values()) + (jid_id,))
- log.info('Save archive infos: %s', kwargs)
+ log.info('Set message archive info: %s %s', jid, kwargs)
self._timeout_commit()
=====================================
gajim/common/modules/mam.py
=====================================
@@ -40,6 +40,9 @@ class MAM(BaseModule):
BaseModule.__init__(self, con)
self.handlers = [
+ StanzaHandler(name='message',
+ callback=self._set_message_archive_info,
+ priority=41),
StanzaHandler(name='message',
callback=self._mam_message_received,
priority=51),
@@ -101,6 +104,42 @@ class MAM(BaseModule):
# A message we received
return properties.mam.id, None
+ def _set_message_archive_info(self, _con, _stanza, properties):
+ if (properties.is_mam_message or
+ properties.is_pubsub or
+ properties.is_muc_subject):
+ return
+
+ if properties.type.is_groupchat:
+ archive_jid = properties.jid.getBare()
+ namespace = muc_caps_cache.get_mam_namespace(archive_jid)
+ timestamp = properties.timestamp
+ if namespace is None:
+ # MUC History
+ app.logger.set_archive_infos(
+ archive_jid,
+ last_muc_timestamp=timestamp)
+ return
+
+ else:
+ archive_jid = self._con.get_own_jid().getBare()
+ namespace = self._con.get_module('MAM').archiving_namespace
+ timestamp = None
+
+ if properties.stanza_id is None or namespace != nbxmpp.NS_MAM_2:
+ return
+
+ if not archive_jid == properties.stanza_id.by:
+ return
+
+ if not self._con.get_module('MAM').is_catch_up_finished(
+ archive_jid):
+ return
+
+ app.logger.set_archive_infos(archive_jid,
+ last_mam_id=properties.stanza_id.id,
+ last_muc_timestamp=timestamp)
+
def _mam_message_received(self, _con, stanza, properties):
if not properties.is_mam_message:
return
=====================================
gajim/common/modules/message.py
=====================================
@@ -293,16 +293,6 @@ class Message(BaseModule):
stanza_id=event.stanza_id,
message_id=event.message_id)
- if muc_caps_cache.has_mam(event.room_jid):
- finished = self._con.get_module('MAM').is_catch_up_finished(
- event.room_jid)
- if not finished:
- return
-
- app.logger.set_archive_infos(event.room_jid,
- last_mam_id=event.stanza_id,
- last_muc_timestamp=event.timestamp)
-
def _check_for_mam_compliance(self, 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:
=====================================
gajim/common/modules/muc.py
=====================================
@@ -19,6 +19,7 @@ import time
import logging
from datetime import datetime
from datetime import timedelta
+from datetime import timezone
from functools import partial
import nbxmpp
@@ -302,13 +303,16 @@ class MUC(BaseModule):
if archive is not None and archive.last_muc_timestamp is not None:
since_epoch = float(archive.last_muc_timestamp)
- since_date = datetime.utcfromtimestamp(since_epoch)
+ since_date = datetime.fromtimestamp(since_epoch, timezone.utc)
if threshold != SyncThreshold.NO_THRESHOLD:
- threshold_date = datetime.utcnow() - timedelta(days=threshold)
+ now = datetime.now(timezone.utc)
+ threshold_date = now - timedelta(days=threshold)
since_date = max(threshold_date, since_date)
date_string = since_date.strftime('%Y-%m-%dT%H:%M:%SZ')
muc_x.setTag('history', {'since': date_string})
+ self._log.info('Request MUC history since: %s (%s)',
+ date_string, since_date.timestamp())
self._log.info('Threshold for %s: %s', room_jid, threshold)
def _on_error_presence(self, _con, _stanza, properties):
=====================================
gajim/session.py
=====================================
@@ -139,12 +139,6 @@ class ChatControlSession:
stanza_id=obj.unique_id,
message_id=obj.message_id)
- jid = self.conn.get_own_jid().getStripped()
- if self.conn.get_module('MAM').is_catch_up_finished(jid):
- app.logger.set_archive_infos(jid,
- last_mam_id=obj.stanza_id,
- last_muc_timestamp=obj.timestamp)
-
if obj.muc_pm and not obj.gc_control:
# This is a carbon of a PM from a MUC we are not currently
# joined. We log it silently without notification.
View it on GitLab:
https://dev.gajim.org/gajim/gajim/compare/66fc682605b7812d4b4c7a3b4833f7d1f2e7e5a6...ca1b2091ca9d2c8a8d6cbe6c8ec5d42b2395f202
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/compare/66fc682605b7812d4b4c7a3b4833f7d1f2e7e5a6...ca1b2091ca9d2c8a8d6cbe6c8ec5d42b2395f202
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits