Fix historical decryption timing issue

This commit is contained in:
Jack Kingsman
2026-01-08 19:04:53 -08:00
parent 9d8229c7be
commit b9fd96ac46
2 changed files with 6 additions and 5 deletions

View File

@@ -429,13 +429,13 @@ class RawPacketRepository:
return row["count"] if row else 0
@staticmethod
async def get_all_undecrypted() -> list[tuple[int, bytes]]:
"""Get all undecrypted packets as (id, data) tuples."""
async def get_all_undecrypted() -> list[tuple[int, bytes, int]]:
"""Get all undecrypted packets as (id, data, timestamp) tuples."""
cursor = await db.conn.execute(
"SELECT id, data FROM raw_packets WHERE decrypted = 0 ORDER BY timestamp ASC"
"SELECT id, data, timestamp FROM raw_packets WHERE decrypted = 0 ORDER BY timestamp ASC"
)
rows = await cursor.fetchall()
return [(row["id"], bytes(row["data"])) for row in rows]
return [(row["id"], bytes(row["data"]), row["timestamp"]) for row in rows]
@staticmethod
async def mark_decrypted(packet_id: int, message_id: int) -> None:

View File

@@ -50,7 +50,7 @@ async def _run_historical_decryption(channel_key_bytes: bytes, channel_key_hex:
logger.info("Starting historical decryption of %d packets", total)
for packet_id, packet_data in packets:
for packet_id, packet_data, packet_timestamp in packets:
result = try_decrypt_packet_with_channel_key(packet_data, channel_key_bytes)
if result is not None:
@@ -68,6 +68,7 @@ async def _run_historical_decryption(channel_key_bytes: bytes, channel_key_hex:
sender=result.sender,
message_text=result.message,
timestamp=result.timestamp,
received_at=packet_timestamp, # Use original packet timestamp for correct ordering
)
if msg_id is not None: