feat(backend): supergroup read receipts are captured like basic groups
This commit is contained in:
1 parent
d8ad62fb59
commit
f27943aae6
1 file changed
+15
-5
@@ -7,25 +7,35 @@ from userbot.modules.raw_json import raw_json
|
||||
from userbot.modules.read_receipts import repository
|
||||
from utils.events import notify_bg_event
|
||||
|
||||
HANDLES = (raw.types.UpdateReadHistoryOutbox,)
|
||||
HANDLES = (raw.types.UpdateReadHistoryOutbox, raw.types.UpdateReadChannelOutbox)
|
||||
|
||||
|
||||
def _watermark(update: raw.base.Update) -> tuple[int, int] | None:
|
||||
if isinstance(update, raw.types.UpdateReadHistoryOutbox):
|
||||
return utils.get_peer_id(update.peer), update.max_id
|
||||
if isinstance(update, raw.types.UpdateReadChannelOutbox):
|
||||
peer = raw.types.PeerChannel(channel_id=update.channel_id)
|
||||
return utils.get_peer_id(peer), update.max_id
|
||||
return None
|
||||
|
||||
|
||||
async def handle(
|
||||
client: PyroClient, update: raw.base.Update, _users: dict, _chats: dict
|
||||
) -> None:
|
||||
ctx = client.capture
|
||||
if ctx is None or not isinstance(update, raw.types.UpdateReadHistoryOutbox):
|
||||
watermark = _watermark(update)
|
||||
if ctx is None or watermark is None:
|
||||
return
|
||||
chat_id = utils.get_peer_id(update.peer)
|
||||
chat_id, max_id = watermark
|
||||
await repository.insert_read(
|
||||
ctx.pool,
|
||||
ctx.account_id,
|
||||
chat_id,
|
||||
chat_id,
|
||||
datetime.now(UTC),
|
||||
update.max_id,
|
||||
max_id,
|
||||
raw_json(update),
|
||||
)
|
||||
await notify_bg_event(
|
||||
ctx.pool, "receipt", ctx.account_id, chat_id=chat_id, message_id=update.max_id
|
||||
ctx.pool, "receipt", ctx.account_id, chat_id=chat_id, message_id=max_id
|
||||
)
|
||||
Reference in new issue
Block a user