core/services/unread.py
Untone b03ac825b6
All checks were successful
deploy / deploy (push) Successful in 27s
unread-fix3
2023-10-16 19:13:39 +03:00

18 lines
505 B
Python

import json
from services.redis import redis
async def get_unread_counter(chat_id: str, author_id: int) -> int:
unread = await redis.execute("LLEN", f"chats/{chat_id}/unread/{author_id}")
return unread or 0
async def get_total_unread_counter(author_id: int) -> int:
chats_set = await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")
unread = 0
for chat_id in list(chats_set):
n = await get_unread_counter(chat_id, author_id)
unread += n
return unread