diff --git a/app/infrastructure/database/repo/report.py b/app/infrastructure/database/repo/report.py index 1125bff..804d94b 100644 --- a/app/infrastructure/database/repo/report.py +++ b/app/infrastructure/database/repo/report.py @@ -23,6 +23,7 @@ async def create( reporter=reporter, reported_user=reported_user, chat=chat, + created_time=command_message.date, command_message_id=command_message.message_id, reported_message_id=reported_message.message_id, reported_message_content=reported_message.html_text, @@ -41,16 +42,21 @@ async def get_linked_pending_reports(self, report_id: int) -> Iterable[Report]: report = await Report.get(id=report_id, using_db=self.session).prefetch_related( "chat" ) - return await ( - Report.filter( - chat=report.chat, - reported_message_id=report.reported_message_id, - status=ReportStatus.PENDING, + return ( + await ( + Report.filter( + chat=report.chat, + reported_message_id=report.reported_message_id, + status=ReportStatus.PENDING, + ) + .prefetch_related("chat", "reporter") + # Sort by `created_time` and command_message_id to get the first report + # If `created_time` is the same, + # the first report is the one with the lowest `command_message_id` + .order_by("created_time", "command_message_id") + .using_db(self.session) + .all() ) - .prefetch_related("chat", "reporter") - .order_by("created_time") - .using_db(self.session) - .all() ) async def has_resolved_report(self, chat_id: int, message_id: int) -> bool: