fix-chat-create
This commit is contained in:
parent
d107562871
commit
e74aacf0fc
|
@ -30,19 +30,21 @@ async def get_total_unread_counter(user_slug: str):
|
||||||
return unread
|
return unread
|
||||||
|
|
||||||
|
|
||||||
async def add_user_to_chat(user_slug: str, chat):
|
async def add_user_to_chat(user_slug: str, chat_id: str, chat=None):
|
||||||
chats_ids = await redis.execute("GET", f"chats_by_user/{user_slug}")
|
chats_ids = await redis.execute("GET", f"chats_by_user/{user_slug}")
|
||||||
|
if not chat:
|
||||||
|
chat = await redis.execute("GET", f"chats/{chat_id}")
|
||||||
if chats_ids:
|
if chats_ids:
|
||||||
chats_ids = list(json.loads(chats_ids))
|
chats_ids = list(json.loads(chats_ids))
|
||||||
else:
|
else:
|
||||||
chats_ids = []
|
chats_ids = []
|
||||||
if chat.id not in chats_ids:
|
if chat_id not in chats_ids:
|
||||||
chats_ids.append(chat.id)
|
chats_ids.append(chat_id)
|
||||||
await redis.execute("SET", f"chats_by_user/{user_slug}", json.dumps(chats_ids))
|
await redis.execute("SET", f"chats_by_user/{user_slug}", json.dumps(chats_ids))
|
||||||
if user_slug not in chat["users"]:
|
if user_slug not in chat["users"]:
|
||||||
chat["users"].append(user_slug)
|
chat["users"].append(user_slug)
|
||||||
chat["updatedAt"] = datetime.now().timestamp()
|
chat["updatedAt"] = datetime.now().timestamp()
|
||||||
await redis.execute("SET", f"chats/{chat.id}", json.dumps(chat))
|
await redis.execute("SET", f"chats/{chat_id}", json.dumps(chat))
|
||||||
return chat
|
return chat
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user