core/services/unread.py
Untone a6c5243c06
All checks were successful
deploy / deploy (push) Successful in 1m23s
viewed-service-fixes
2023-12-17 23:30:20 +03:00

17 lines
532 B
Python

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