Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
922fa4f1
by Philipp Hörist at 2019-08-05T20:49:00Z
-
dce96b5f
by Philipp Hörist at 2019-08-05T21:05:30Z
-
ca1b2091
by Philipp Hörist at 2019-08-05T21:58:16Z
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:
| ... | ... | @@ -1463,5 +1463,5 @@ class Logger: |
| 1463 | 1463 |
sql = '''UPDATE last_archive_message SET {}
|
| 1464 | 1464 |
WHERE jid_id = ?'''.format(args)
|
| 1465 | 1465 |
self._con.execute(sql, tuple(kwargs.values()) + (jid_id,))
|
| 1466 |
- log.info('Save archive infos: %s', kwargs)
|
|
| 1466 |
+ log.info('Set message archive info: %s %s', jid, kwargs)
|
|
| 1467 | 1467 |
self._timeout_commit()
|
| ... | ... | @@ -40,6 +40,9 @@ class MAM(BaseModule): |
| 40 | 40 |
BaseModule.__init__(self, con)
|
| 41 | 41 |
|
| 42 | 42 |
self.handlers = [
|
| 43 |
+ StanzaHandler(name='message',
|
|
| 44 |
+ callback=self._set_message_archive_info,
|
|
| 45 |
+ priority=41),
|
|
| 43 | 46 |
StanzaHandler(name='message',
|
| 44 | 47 |
callback=self._mam_message_received,
|
| 45 | 48 |
priority=51),
|
| ... | ... | @@ -101,6 +104,42 @@ class MAM(BaseModule): |
| 101 | 104 |
# A message we received
|
| 102 | 105 |
return properties.mam.id, None
|
| 103 | 106 |
|
| 107 |
+ def _set_message_archive_info(self, _con, _stanza, properties):
|
|
| 108 |
+ if (properties.is_mam_message or
|
|
| 109 |
+ properties.is_pubsub or
|
|
| 110 |
+ properties.is_muc_subject):
|
|
| 111 |
+ return
|
|
| 112 |
+ |
|
| 113 |
+ if properties.type.is_groupchat:
|
|
| 114 |
+ archive_jid = properties.jid.getBare()
|
|
| 115 |
+ namespace = muc_caps_cache.get_mam_namespace(archive_jid)
|
|
| 116 |
+ timestamp = properties.timestamp
|
|
| 117 |
+ if namespace is None:
|
|
| 118 |
+ # MUC History
|
|
| 119 |
+ app.logger.set_archive_infos(
|
|
| 120 |
+ archive_jid,
|
|
| 121 |
+ last_muc_timestamp=timestamp)
|
|
| 122 |
+ return
|
|
| 123 |
+ |
|
| 124 |
+ else:
|
|
| 125 |
+ archive_jid = self._con.get_own_jid().getBare()
|
|
| 126 |
+ namespace = self._con.get_module('MAM').archiving_namespace
|
|
| 127 |
+ timestamp = None
|
|
| 128 |
+ |
|
| 129 |
+ if properties.stanza_id is None or namespace != nbxmpp.NS_MAM_2:
|
|
| 130 |
+ return
|
|
| 131 |
+ |
|
| 132 |
+ if not archive_jid == properties.stanza_id.by:
|
|
| 133 |
+ return
|
|
| 134 |
+ |
|
| 135 |
+ if not self._con.get_module('MAM').is_catch_up_finished(
|
|
| 136 |
+ archive_jid):
|
|
| 137 |
+ return
|
|
| 138 |
+ |
|
| 139 |
+ app.logger.set_archive_infos(archive_jid,
|
|
| 140 |
+ last_mam_id=properties.stanza_id.id,
|
|
| 141 |
+ last_muc_timestamp=timestamp)
|
|
| 142 |
+ |
|
| 104 | 143 |
def _mam_message_received(self, _con, stanza, properties):
|
| 105 | 144 |
if not properties.is_mam_message:
|
| 106 | 145 |
return
|
| ... | ... | @@ -293,16 +293,6 @@ class Message(BaseModule): |
| 293 | 293 |
stanza_id=event.stanza_id,
|
| 294 | 294 |
message_id=event.message_id)
|
| 295 | 295 |
|
| 296 |
- if muc_caps_cache.has_mam(event.room_jid):
|
|
| 297 |
- finished = self._con.get_module('MAM').is_catch_up_finished(
|
|
| 298 |
- event.room_jid)
|
|
| 299 |
- if not finished:
|
|
| 300 |
- return
|
|
| 301 |
- |
|
| 302 |
- app.logger.set_archive_infos(event.room_jid,
|
|
| 303 |
- last_mam_id=event.stanza_id,
|
|
| 304 |
- last_muc_timestamp=event.timestamp)
|
|
| 305 |
- |
|
| 306 | 296 |
def _check_for_mam_compliance(self, room_jid, stanza_id):
|
| 307 | 297 |
namespace = caps_cache.muc_caps_cache.get_mam_namespace(room_jid)
|
| 308 | 298 |
if stanza_id is None and namespace == nbxmpp.NS_MAM_2:
|
| ... | ... | @@ -19,6 +19,7 @@ import time |
| 19 | 19 |
import logging
|
| 20 | 20 |
from datetime import datetime
|
| 21 | 21 |
from datetime import timedelta
|
| 22 |
+from datetime import timezone
|
|
| 22 | 23 |
from functools import partial
|
| 23 | 24 |
|
| 24 | 25 |
import nbxmpp
|
| ... | ... | @@ -302,13 +303,16 @@ class MUC(BaseModule): |
| 302 | 303 |
if archive is not None and archive.last_muc_timestamp is not None:
|
| 303 | 304 |
since_epoch = float(archive.last_muc_timestamp)
|
| 304 | 305 |
|
| 305 |
- since_date = datetime.utcfromtimestamp(since_epoch)
|
|
| 306 |
+ since_date = datetime.fromtimestamp(since_epoch, timezone.utc)
|
|
| 306 | 307 |
if threshold != SyncThreshold.NO_THRESHOLD:
|
| 307 |
- threshold_date = datetime.utcnow() - timedelta(days=threshold)
|
|
| 308 |
+ now = datetime.now(timezone.utc)
|
|
| 309 |
+ threshold_date = now - timedelta(days=threshold)
|
|
| 308 | 310 |
since_date = max(threshold_date, since_date)
|
| 309 | 311 |
|
| 310 | 312 |
date_string = since_date.strftime('%Y-%m-%dT%H:%M:%SZ')
|
| 311 | 313 |
muc_x.setTag('history', {'since': date_string})
|
| 314 |
+ self._log.info('Request MUC history since: %s (%s)',
|
|
| 315 |
+ date_string, since_date.timestamp())
|
|
| 312 | 316 |
self._log.info('Threshold for %s: %s', room_jid, threshold)
|
| 313 | 317 |
|
| 314 | 318 |
def _on_error_presence(self, _con, _stanza, properties):
|
| ... | ... | @@ -139,12 +139,6 @@ class ChatControlSession: |
| 139 | 139 |
stanza_id=obj.unique_id,
|
| 140 | 140 |
message_id=obj.message_id)
|
| 141 | 141 |
|
| 142 |
- jid = self.conn.get_own_jid().getStripped()
|
|
| 143 |
- if self.conn.get_module('MAM').is_catch_up_finished(jid):
|
|
| 144 |
- app.logger.set_archive_infos(jid,
|
|
| 145 |
- last_mam_id=obj.stanza_id,
|
|
| 146 |
- last_muc_timestamp=obj.timestamp)
|
|
| 147 |
- |
|
| 148 | 142 |
if obj.muc_pm and not obj.gc_control:
|
| 149 | 143 |
# This is a carbon of a PM from a MUC we are not currently
|
| 150 | 144 |
# joined. We log it silently without notification.
|