author-getting-fix
All checks were successful
deploy / deploy (push) Successful in 1m4s

This commit is contained in:
2023-12-19 17:24:52 +03:00
parent d75f31072c
commit 8c1f52f99b
5 changed files with 67 additions and 55 deletions

View File

@@ -6,7 +6,7 @@ from models.chat import ChatPayload, Message
from models.member import ChatMember
from resolvers.chats import create_chat
from services.auth import login_required
from services.core import authors_by_id, get_my_followed
from services.core import authors_by_id, get_my_followed, authors_by_user
from services.rediscache import redis
from services.schema import query
@@ -52,7 +52,9 @@ async def load_messages(
@login_required
async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Union[List[Dict[str, Any]], None]]:
"""load :limit chats of current user with :offset"""
author_id = info.context.get("author_id")
user_id = info.context["user_id"]
author = authors_by_user[user_id]
author_id = author["id"]
chats = []
if author_id:
cids = await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")
@@ -88,13 +90,15 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Uni
@login_required
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"]
user_chats = (await redis.execute("SMEMBERS", "chats_by_author/" + str(author_id))) or []
user_chats = [c for c in user_chats]
if user_chats:
user_id = info.context["user_id"]
author = authors_by_user[user_id]
author_id = author["id"]
author_chats = (await redis.execute("SMEMBERS", "chats_by_author/" + str(author_id))) or []
author_chats = [c for c in author_chats]
if author_chats:
messages = []
by_chat = by.get("chat")
if by_chat in user_chats:
if by_chat in author_chats:
chat = await redis.execute("GET", f"chats/{by_chat}")
if not chat:
return {"messages": [], "error": "chat not exist"}