@@ -465,6 +465,7 @@ def get_messages_for(
465
465
self ,
466
466
user : Optional [User ],
467
467
* ,
468
+ sequence : Optional [int ] = None ,
468
469
after : Optional [int ] = None ,
469
470
before : Optional [int ] = None ,
470
471
recent : bool = False ,
@@ -477,7 +478,12 @@ def get_messages_for(
477
478
whispers meant to be displayed to moderators.
478
479
479
480
Exactly one of `after`, `begin`, `recent` or `single` must be specified:
480
- - `after=N` returns messages with ids greater than N in ascending order
481
+ - `sequence=N` returns messages that have been posted, edited, or deleted since the given
482
+ `seqno` (that is: the have seqno greater than N). Messages are returned in sequence
483
+ order.
484
+ - `after=N` returns messages with ids greater than N in ascending order. This is normally
485
+ *not* what you want for fetching messages as it omits edits and deletions; typically you
486
+ want to retrieve by seqno instead.
481
487
- `before=N` returns messages with ids less than N in descending order
482
488
- `recent=True` returns the most recent messages in descending order
483
489
- `single=123` returns a singleton list containing the single message with the given message
@@ -491,11 +497,15 @@ def get_messages_for(
491
497
mod = self .check_moderator (user )
492
498
msgs = []
493
499
494
- opt_count = sum (( after is not None , before is not None , recent , single is not None ) )
500
+ opt_count = sum (arg is not None for arg in ( sequence , after , before , single )) + bool ( recent )
495
501
if opt_count == 0 :
496
- raise RuntimeError ("Exactly one of before=, after=, recent=, or single= is required" )
502
+ raise RuntimeError (
503
+ "Exactly one of sequence=, before=, after=, recent=, or single= is required"
504
+ )
497
505
if opt_count > 1 :
498
- raise RuntimeError ("Cannot specify more than one of before=, after=, recent=, single=" )
506
+ raise RuntimeError (
507
+ "Cannot specify more than one of sequence=, before=, after=, recent=, single="
508
+ )
499
509
500
510
# Handle id mapping from an old database import in case the client is requesting
501
511
# messages since some id from the old db.
@@ -525,8 +535,9 @@ def get_messages_for(
525
535
for row in query (
526
536
f"""
527
537
SELECT * FROM message_details
528
- WHERE room = :r AND data IS NOT NULL AND NOT filtered
538
+ WHERE room = :r AND NOT filtered { 'AND data IS NOT NULL' if sequence is None else '' }
529
539
{
540
+ 'AND seqno > :sequence' if sequence is not None else
530
541
'AND id > :after' if after is not None else
531
542
'AND id < :before' if before is not None else
532
543
'AND id = :single' if single is not None else
@@ -535,11 +546,13 @@ def get_messages_for(
535
546
AND ({ whisper_clause } )
536
547
{
537
548
'' if single is not None else
549
+ 'ORDER BY seqno ASC LIMIT :limit' if sequence is not None else
538
550
'ORDER BY id ASC LIMIT :limit' if after is not None else
539
551
'ORDER BY id DESC LIMIT :limit'
540
552
}
541
553
""" ,
542
554
r = self .id ,
555
+ sequence = sequence ,
543
556
after = after ,
544
557
before = before ,
545
558
single = single ,
0 commit comments