Skip to content

Commit 4ec6364

Browse files
committed
apply room post id hax for message deletion
* make application of room post id workarround a utils function * apply room post id workaround for deleted message ids too
1 parent b65f8d4 commit 4ec6364

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

sogs/model.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ def add_post_to_room(user_id, room_id, data, sig, rate_limit_size=5, rate_limit_
573573

574574

575575
def get_deletions_deprecated(room_id, since):
576+
since = utils.maybe_apply_post_id_hax(room_id, since)
576577
if since:
577578
result = db.conn.execute(
578579
"""
@@ -591,20 +592,14 @@ def get_deletions_deprecated(room_id, since):
591592
""",
592593
[room_id],
593594
)
594-
return [{'deleted_message_id': row[0], 'id': row[1]} for row in result]
595+
return [{'deleted_message_id': int(row[0]), 'id': int(row[1])} for row in result]
595596

596597

597598
def get_message_deprecated(room_id, since, limit=256):
598599
msgs = list()
599600
result = None
601+
since = utils.maybe_apply_post_id_hax(room_id, since)
600602
if since:
601-
# Handle id mapping from an old database import in case the client is requesting
602-
# messages since some id from the old db.
603-
if db.ROOM_IMPORT_HACKS and room_id in db.ROOM_IMPORT_HACKS:
604-
(max_old_id, offset) = db.ROOM_IMPORT_HACKS[room_id]
605-
if since <= max_old_id:
606-
since += offset
607-
608603
result = db.conn.execute(
609604
"""
610605
SELECT * FROM message_details

sogs/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ def server_url(room):
6161
return '{}/{}?public_key={}'.format(config.URL_BASE, room or '', crypto.server_pubkey_hex)
6262

6363

64+
def maybe_apply_post_id_hax(room_id, since):
65+
"""Handle id mapping from an old database import in case the client is requesting messages since some id from the old db."""
66+
if since and db.ROOM_IMPORT_HACKS and room_id in db.ROOM_IMPORT_HACKS:
67+
(max_old_id, offset) = db.ROOM_IMPORT_HACKS[room_id]
68+
if since <= max_old_id:
69+
since += offset
70+
return since
71+
72+
6473
SIGNATURE_SIZE = 64
6574
SESSION_ID_SIZE = 33
6675
# Size returned by make_legacy_token (assuming it is given a standard 66-hex (33 byte) session id):

0 commit comments

Comments
 (0)