| ... |
... |
@@ -264,7 +264,7 @@ class MAM(BaseModule): |
|
264
|
264
|
own_jid = self._con.get_own_jid().getBare()
|
|
265
|
265
|
|
|
266
|
266
|
if own_jid in self._mam_query_ids:
|
|
267
|
|
- self._log.warning('MAM request for %s already running', own_jid)
|
|
|
267
|
+ self._log.warning('Request already running: %s', own_jid)
|
|
268
|
268
|
return
|
|
269
|
269
|
|
|
270
|
270
|
archive = app.logger.get_archive_infos(own_jid)
|
| ... |
... |
@@ -281,12 +281,14 @@ class MAM(BaseModule): |
|
281
|
281
|
start_date = None
|
|
282
|
282
|
queryid = self._get_query_id(own_jid)
|
|
283
|
283
|
if mam_id:
|
|
284
|
|
- self._log.info('MAM query after: %s', mam_id)
|
|
|
284
|
+ self._log.info('Request archive: %s, after mam-id %s',
|
|
|
285
|
+ own_jid, mam_id)
|
|
285
|
286
|
|
|
286
|
287
|
else:
|
|
287
|
288
|
# First Start, we request the last week
|
|
288
|
289
|
start_date = datetime.utcnow() - timedelta(days=7)
|
|
289
|
|
- self._log.info('First start: query archive start: %s', start_date)
|
|
|
290
|
+ self._log.info('Request archive: %s, after date %s',
|
|
|
291
|
+ own_jid, start_date)
|
|
290
|
292
|
|
|
291
|
293
|
self._nbxmpp('MAM').make_query(own_jid,
|
|
292
|
294
|
queryid,
|
| ... |
... |
@@ -310,14 +312,14 @@ class MAM(BaseModule): |
|
310
|
312
|
if archive is None or archive.last_mam_id is None:
|
|
311
|
313
|
# First join
|
|
312
|
314
|
start_date = datetime.utcnow() - timedelta(days=1)
|
|
313
|
|
- self._log.info('First join: query archive %s from: %s',
|
|
|
315
|
+ self._log.info('Request archive: %s, after date %s',
|
|
314
|
316
|
jid, start_date)
|
|
315
|
317
|
|
|
316
|
318
|
elif threshold == SyncThreshold.NO_THRESHOLD:
|
|
317
|
319
|
# Not our first join and no threshold set
|
|
318
|
320
|
|
|
319
|
321
|
mam_id = archive.last_mam_id
|
|
320
|
|
- self._log.info('Request from archive: %s, after mam-id %s',
|
|
|
322
|
+ self._log.info('Request archive: %s, after mam-id %s',
|
|
321
|
323
|
jid, archive.last_mam_id)
|
|
322
|
324
|
|
|
323
|
325
|
else:
|
| ... |
... |
@@ -325,7 +327,7 @@ class MAM(BaseModule): |
|
325
|
327
|
# last join and check against threshold
|
|
326
|
328
|
last_timestamp = archive.last_muc_timestamp
|
|
327
|
329
|
if last_timestamp is None:
|
|
328
|
|
- self._log.info('No last muc timestamp found')
|
|
|
330
|
+ self._log.info('No last muc timestamp found: %s', jid)
|
|
329
|
331
|
last_timestamp = 0
|
|
330
|
332
|
|
|
331
|
333
|
last = datetime.utcfromtimestamp(float(last_timestamp))
|
| ... |
... |
@@ -333,13 +335,13 @@ class MAM(BaseModule): |
|
333
|
335
|
# To much time has elapsed since last join, apply threshold
|
|
334
|
336
|
start_date = datetime.utcnow() - timedelta(days=threshold)
|
|
335
|
337
|
self._log.info('Too much time elapsed since last join, '
|
|
336
|
|
- 'request from: %s, threshold: %s',
|
|
337
|
|
- start_date, threshold)
|
|
|
338
|
+ 'request archive: %s, after date %s, '
|
|
|
339
|
+ 'threshold: %s', jid, start_date, threshold)
|
|
338
|
340
|
|
|
339
|
341
|
else:
|
|
340
|
342
|
# Request from last mam-id
|
|
341
|
343
|
mam_id = archive.last_mam_id
|
|
342
|
|
- self._log.info('Request from archive %s after %s:',
|
|
|
344
|
+ self._log.info('Request archive: %s, after mam-id %s:',
|
|
343
|
345
|
jid, archive.last_mam_id)
|
|
344
|
346
|
|
|
345
|
347
|
if jid in self._catch_up_finished:
|
| ... |
... |
@@ -368,12 +370,28 @@ class MAM(BaseModule): |
|
368
|
370
|
self.request_archive_on_signin()
|
|
369
|
371
|
return
|
|
370
|
372
|
|
|
371
|
|
- if result.rsm.last is None:
|
|
372
|
|
- self._log.info('MAM catchup finished: %s', result.jid)
|
|
|
373
|
+ if result.complete:
|
|
373
|
374
|
self._catch_up_finished.append(result.jid)
|
|
374
|
|
- return
|
|
|
375
|
+ self._log.info('Request finished: %s, last mam id: %s',
|
|
|
376
|
+ result.jid, result.rsm.last)
|
|
|
377
|
+
|
|
|
378
|
+ if result.rsm.last is not None:
|
|
|
379
|
+ # <last> is not provided if the requested page was empty
|
|
|
380
|
+ # so this means we did not get anything hence we only need
|
|
|
381
|
+ # to update the archive info if <last> is present
|
|
|
382
|
+ app.logger.set_archive_infos(result.jid,
|
|
|
383
|
+ last_mam_id=result.rsm.last,
|
|
|
384
|
+ last_muc_timestamp=time.time())
|
|
375
|
385
|
|
|
376
|
|
- if not result.complete:
|
|
|
386
|
+ if start_date is not None and not groupchat:
|
|
|
387
|
+ # Record the earliest timestamp we request from
|
|
|
388
|
+ # the account archive. For the account archive we only
|
|
|
389
|
+ # set start_date at the very first request.
|
|
|
390
|
+ app.logger.set_archive_infos(
|
|
|
391
|
+ result.jid,
|
|
|
392
|
+ oldest_mam_timestamp=start_date.timestamp())
|
|
|
393
|
+
|
|
|
394
|
+ else:
|
|
377
|
395
|
app.logger.set_archive_infos(result.jid,
|
|
378
|
396
|
last_mam_id=result.rsm.last)
|
|
379
|
397
|
queryid = self._get_query_id(result.jid)
|
| ... |
... |
@@ -386,36 +404,20 @@ class MAM(BaseModule): |
|
386
|
404
|
'start': None,
|
|
387
|
405
|
'groupchat': groupchat})
|
|
388
|
406
|
|
|
389
|
|
- else:
|
|
390
|
|
- app.logger.set_archive_infos(result.jid,
|
|
391
|
|
- last_mam_id=result.rsm.last,
|
|
392
|
|
- last_muc_timestamp=time.time())
|
|
393
|
|
-
|
|
394
|
|
- if start_date is not None and not groupchat:
|
|
395
|
|
- # Record the earliest timestamp we request from
|
|
396
|
|
- # the account archive. For the account archive we only
|
|
397
|
|
- # set start_date at the very first request.
|
|
398
|
|
- app.logger.set_archive_infos(
|
|
399
|
|
- result.jid,
|
|
400
|
|
- oldest_mam_timestamp=start_date.timestamp())
|
|
401
|
|
-
|
|
402
|
|
- self._catch_up_finished.append(result.jid)
|
|
403
|
|
- self._log.info('End of MAM query, last mam id: %s',
|
|
404
|
|
- result.rsm.last)
|
|
405
|
|
-
|
|
406
|
407
|
def request_archive_interval(self,
|
|
407
|
408
|
start_date,
|
|
408
|
409
|
end_date,
|
|
409
|
410
|
after=None,
|
|
410
|
411
|
queryid=None):
|
|
411
|
412
|
|
|
|
413
|
+ jid = self._con.get_own_jid().getBare()
|
|
|
414
|
+
|
|
412
|
415
|
if after is None:
|
|
413
|
|
- self._log.info('Request interval from %s to %s',
|
|
414
|
|
- start_date, end_date)
|
|
|
416
|
+ self._log.info('Request interval: %s, from %s to %s',
|
|
|
417
|
+ jid, start_date, end_date)
|
|
415
|
418
|
else:
|
|
416
|
|
- self._log.info('Query page after %s', after)
|
|
|
419
|
+ self._log.info('Request page: %s, after %s', jid, after)
|
|
417
|
420
|
|
|
418
|
|
- jid = self._con.get_own_jid().getBare()
|
|
419
|
421
|
if queryid is None:
|
|
420
|
422
|
queryid = self._get_query_id(jid)
|
|
421
|
423
|
self._mam_query_ids[jid] = queryid
|
| ... |
... |
@@ -443,30 +445,21 @@ class MAM(BaseModule): |
|
443
|
445
|
else:
|
|
444
|
446
|
timestamp = ArchiveState.ALL
|
|
445
|
447
|
|
|
446
|
|
- if result.rsm.last is None:
|
|
|
448
|
+ if result.complete:
|
|
|
449
|
+ self._log.info('Request finished: %s, last mam id: %s',
|
|
|
450
|
+ result.jid, result.rsm.last)
|
|
|
451
|
+ app.logger.set_archive_infos(result.jid,
|
|
|
452
|
+ oldest_mam_timestamp=timestamp)
|
|
447
|
453
|
app.nec.push_incoming_event(NetworkEvent(
|
|
448
|
454
|
'archiving-interval-finished',
|
|
449
|
455
|
account=self._account,
|
|
450
|
456
|
query_id=queryid))
|
|
451
|
457
|
|
|
452
|
|
- app.logger.set_archive_infos(result.jid,
|
|
453
|
|
- oldest_mam_timestamp=timestamp)
|
|
454
|
|
- self._log.info('End of MAM request, no items retrieved')
|
|
455
|
|
- return
|
|
456
|
|
-
|
|
457
|
|
- if not result.complete:
|
|
|
458
|
+ else:
|
|
458
|
459
|
self.request_archive_interval(start_date,
|
|
459
|
460
|
end_date,
|
|
460
|
461
|
result.rsm.last,
|
|
461
|
462
|
queryid)
|
|
462
|
|
- else:
|
|
463
|
|
- self._log.info('Request finished')
|
|
464
|
|
- app.logger.set_archive_infos(result.jid,
|
|
465
|
|
- oldest_mam_timestamp=timestamp)
|
|
466
|
|
- app.nec.push_incoming_event(NetworkEvent(
|
|
467
|
|
- 'archiving-interval-finished',
|
|
468
|
|
- account=self._account,
|
|
469
|
|
- query_id=queryid))
|
|
470
|
463
|
|
|
471
|
464
|
|
|
472
|
465
|
def get_instance(*args, **kwargs):
|