Skip to content

Commit 650ded2

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 f8818d7 commit 650ded2

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
@@ -572,6 +572,7 @@ def add_post_to_room(user_id, room_id, data, sig, rate_limit_size=5, rate_limit_
572572

573573

574574
def get_deletions_deprecated(room_id, since):
575+
since = utils.maybe_apply_post_id_hax(room_id, since)
575576
if since:
576577
result = db.conn.execute(
577578
"""
@@ -590,20 +591,14 @@ def get_deletions_deprecated(room_id, since):
590591
""",
591592
[room_id],
592593
)
593-
return [{'deleted_message_id': row[0], 'id': row[1]} for row in result]
594+
return [{'deleted_message_id': int(row[0]), 'id': int(row[1])} for row in result]
594595

595596

596597
def get_message_deprecated(room_id, since, limit=256):
597598
msgs = list()
598599
result = None
600+
since = utils.maybe_apply_post_id_hax(room_id, since)
599601
if since:
600-
# Handle id mapping from an old database import in case the client is requesting
601-
# messages since some id from the old db.
602-
if db.ROOM_IMPORT_HACKS and room_id in db.ROOM_IMPORT_HACKS:
603-
(max_old_id, offset) = db.ROOM_IMPORT_HACKS[room_id]
604-
if since <= max_old_id:
605-
since += offset
606-
607602
result = db.conn.execute(
608603
"""
609604
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)