calculate totalUnreadMessages for user

This commit is contained in:
knst-kotov
2022-04-13 15:11:06 +03:00
parent 5b4cc95e87
commit c4bda0b1c3
3 changed files with 21 additions and 1 deletions

View File

@@ -42,6 +42,19 @@ class MessageResult:
self.status = status
self.message = message
async def get_total_unread_messages_for_user(user_slug):
chats = await redis.execute("GET", f"chats_by_user/{user_slug}")
if not chats:
return 0
chats = json.loads(chats)
total = 0
for chat_id in chats:
n = await redis.execute("LLEN", f"chats/{chat_id}/unread/{user_slug}")
total += n
return total
async def add_user_to_chat(user_slug, chat_id, chat = None):
chats = await redis.execute("GET", f"chats_by_user/{user_slug}")
if not chats: