inbox-debug-2

This commit is contained in:
Untone 2024-01-24 12:51:16 +03:00
parent 636b5446a2
commit 6e8c084816

View File

@ -65,6 +65,7 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Uni
"""load :limit chats of current user with :offset"""
author_id = info.context["author_id"]
chats = []
try:
if author_id:
logger.debug("got author", author_id)
cids = await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")
@ -103,6 +104,10 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Uni
else:
logger.error(f"cant find chat by id {cid}")
except Exception as error:
import traceback
traceback.print_exc()
return {"chats": chats, "error": None}
@ -111,7 +116,8 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Uni
async def load_messages_by(_, info, by, limit: int = 10, offset: int = 0):
"""load :limit messages of :chat_id with :offset"""
author_id = info.context["author_id"]
author_chats = await redis.execute("SMEMBERS", "chats_by_author/" + str(author_id))
author_chats = await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")
try:
if isinstance(author_chats, set):
author_chats = list(author_chats)
messages = []
@ -131,4 +137,9 @@ async def load_messages_by(_, info, by, limit: int = 10, offset: int = 0):
),
"error": None,
}
except Exception as error:
import traceback
traceback.print_exc()
return {"error": "Cannot get messages of this chat"}