This commit is contained in:
2023-10-13 19:45:30 +03:00
parent 1c46fc1d48
commit 84e6841331
8 changed files with 84 additions and 73 deletions

View File

@@ -4,18 +4,15 @@ import json
from services.auth import login_required
async def get_unread_counter(chat_id: str, author_id: int):
async def get_unread_counter(chat_id: str, author_id: int) -> int:
try:
unread = await redis.execute(
"LLEN", f"chats/{chat_id}/unread/{author_id}"
)
if unread:
return unread
unread = await redis.execute("LLEN", f"chats/{chat_id}/unread/{author_id}")
return unread or 0
except Exception:
return 0
async def get_total_unread_counter(author_id: int):
async def get_total_unread_counter(author_id: int) -> int:
chats = await redis.execute("GET", f"chats_by_author/{author_id}")
unread = 0
if chats: