fix-unread
This commit is contained in:
parent
582a21408e
commit
0c75902a64
|
@ -1,22 +1,19 @@
|
||||||
from services.redis import redis
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from services.redis import redis
|
||||||
|
|
||||||
async def get_unread_counter(chat_id: str, author_id: int):
|
|
||||||
try:
|
async def get_unread_counter(chat_id: str, author_id: int) -> int:
|
||||||
unread = await redis.execute(
|
unread = await redis.execute("LLEN", f"chats/{chat_id}/unread/{author_id}")
|
||||||
"LLEN", f"chats/{chat_id}/unread/{author_id}"
|
|
||||||
)
|
|
||||||
return unread or 0
|
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:
|
||||||
print(f"[services.unread] get_total_unread_counter({author_id})")
|
chats = await redis.execute("GET", f"chats_by_author/{author_id}")
|
||||||
chats = await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")
|
|
||||||
unread = 0
|
unread = 0
|
||||||
for chat_id in list(chats):
|
if chats:
|
||||||
n = await get_unread_counter(chat_id, author_id)
|
chats = json.loads(chats)
|
||||||
|
for chat_id in chats:
|
||||||
|
n = await get_unread_counter(chat_id.decode("utf-8"), author_id)
|
||||||
unread += n
|
unread += n
|
||||||
return unread
|
return unread
|
||||||
|
|
Loading…
Reference in New Issue
Block a user