core/resolvers/inbox/unread.py

11 lines
280 B
Python
Raw Normal View History

2022-11-21 08:13:57 +00:00
from base.redis import redis
2022-12-02 08:47:55 +00:00
async def get_unread_counter(chat_id: str, user_id: int):
2022-11-21 08:13:57 +00:00
try:
2022-12-02 08:47:55 +00:00
unread = await redis.execute("LLEN", f"chats/{chat_id.decode('utf-8')}/unread/{user_id}")
2022-11-21 08:13:57 +00:00
if unread:
return unread
except Exception:
return 0