diff --git a/app/repository.py b/app/repository.py index 386e10c..5ddf827 100644 --- a/app/repository.py +++ b/app/repository.py @@ -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: diff --git a/app/routers/packets.py b/app/routers/packets.py index 3e5bae9..177a68d 100644 --- a/app/routers/packets.py +++ b/app/routers/packets.py @@ -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: