This commit is contained in:
Untone 2023-10-13 02:20:10 +03:00
parent ebedc362b2
commit 975be32af1

View File

@ -45,14 +45,13 @@ async def load_messages(chat_id: str, limit: int = 5, offset: int = 0, ids=None)
async def load_chats(_, info, limit: int = 50, offset: int = 0): async def load_chats(_, info, limit: int = 50, offset: int = 0):
"""load :limit chats of current user with :offset""" """load :limit chats of current user with :offset"""
author_id = info.context["author_id"] author_id = info.context["author_id"]
cids = list( cids = (list(await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")) or []
(await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")) or [] )[offset:(offset + limit)]
)[offset : offset + limit]
members_online = (await redis.execute("SMEMBERS", "authors-online")) or [] members_online = (await redis.execute("SMEMBERS", "authors-online")) or []
chats = [] chats = []
if len(cids) == 0: if len(cids) == 0:
print(f"[resolvers.load] no chats for user with id={author_id}, create one with Discours (id=2)") print(f"[resolvers.load] no chats for user with id={author_id}, create one with Discours (id=2)")
r = await create_chat(None, info, members=[2]) # member with id = 1 is discours r = await create_chat(None, info, members=[2]) # member with id = 2 is discours
cids.append(r["chat"]["id"]) cids.append(r["chat"]["id"])
for cid in cids: for cid in cids:
c = await redis.execute("GET", f"chats/{cid}") c = await redis.execute("GET", f"chats/{cid}")