From 97ccfbbffd3b68a586510c3a37f98fec24435de7 Mon Sep 17 00:00:00 2001 From: h Date: Mon, 19 Oct 2026 02:44:11 +0000 Subject: [PATCH] fix(backend): watch times stay in utc for naive telegram dates, webhook outbox survives a database hiccup at start --- backend/src/api/webhooks.py | 5 ++++- backend/src/userbot/modules/watches/cache.py | 4 ++-- backend/src/userbot/modules/watches/seen.py | 10 ++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/backend/src/api/webhooks.py b/backend/src/api/webhooks.py index fe36757..34bcd4c 100644 --- a/backend/src/api/webhooks.py +++ b/backend/src/api/webhooks.py @@ -155,11 +155,14 @@ class Outbox: self._wake.set() async def run(self, pool: asyncpg.Pool) -> None: - await webhooks_read.release_stuck(pool) + released = False async with new_client() as client: while True: self._wake.clear() try: + if not released: + await webhooks_read.release_stuck(pool) + released = True await self._drain(pool, client) delay = await self._delay(pool) except Exception: diff --git a/backend/src/userbot/modules/watches/cache.py b/backend/src/userbot/modules/watches/cache.py index 965dc26..b5865e8 100644 --- a/backend/src/userbot/modules/watches/cache.py +++ b/backend/src/userbot/modules/watches/cache.py @@ -1,6 +1,6 @@ from __future__ import annotations -from datetime import datetime, timedelta +from datetime import UTC, datetime, timedelta from typing import TYPE_CHECKING, Any from userbot.modules.watches import repository @@ -159,7 +159,7 @@ class WatchCache: if not watch_ids: return if status != "online": - self._last_seen[peer_id] = last_online or at + self._last_seen[peer_id] = (last_online or at).astimezone(UTC) return await self._guard(self._on_online(peer_id, at, watch_ids)) diff --git a/backend/src/userbot/modules/watches/seen.py b/backend/src/userbot/modules/watches/seen.py index 07782b9..112428c 100644 --- a/backend/src/userbot/modules/watches/seen.py +++ b/backend/src/userbot/modules/watches/seen.py @@ -1,9 +1,15 @@ +from datetime import UTC, datetime + from pyrogram.types import Message from userbot.modules.capture.message import sender_id from userbot.modules.watches.evaluator import Seen +def utc(moment: datetime | None) -> datetime | None: + return moment.astimezone(UTC) if moment else None + + def seen_message(chat_id: int, message: Message) -> Seen: return Seen( chat_id=chat_id, @@ -11,6 +17,6 @@ def seen_message(chat_id: int, message: Message) -> Seen: sender_id=sender_id(message), text=message.text or message.caption, outgoing=bool(message.outgoing), - date=message.date, - edit_date=message.edit_date, + date=utc(message.date), + edit_date=utc(message.edit_date), )