2023-10-23 14:47:11 +00:00
|
|
|
from services.rediscache import redis
|
2023-10-16 14:50:05 +00:00
|
|
|
|
2023-10-05 19:59:50 +00:00
|
|
|
|
2023-10-16 14:50:05 +00:00
|
|
|
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
|
2023-10-05 19:59:50 +00:00
|
|
|
|
|
|
|
|
2023-10-16 14:50:05 +00:00
|
|
|
async def get_total_unread_counter(author_id: int) -> int:
|
2023-10-16 16:00:18 +00:00
|
|
|
chats_set = await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")
|
2023-10-05 19:59:50 +00:00
|
|
|
unread = 0
|
2023-10-16 16:00:18 +00:00
|
|
|
for chat_id in list(chats_set):
|
2023-10-16 16:13:39 +00:00
|
|
|
n = await get_unread_counter(chat_id, author_id)
|
2023-10-16 16:00:18 +00:00
|
|
|
unread += n
|
2023-10-05 19:59:50 +00:00
|
|
|
return unread
|