format+fix
Some checks failed
deploy / deploy (push) Failing after 1m7s

This commit is contained in:
2023-11-14 21:25:55 +03:00
parent 4f3a0dc788
commit 4ecdc08dfc
6 changed files with 20 additions and 21 deletions

View File

@@ -99,4 +99,4 @@ async def delete_chat(_, info, chat_id: str):
await redis.execute("DEL", f"chats/{chat_id}")
await redis.execute("SREM", f"chats_by_author/{author_id}", chat_id)
else:
return {"error": "chat not exist"}
return {"error": "chat not exist"}

View File

@@ -3,7 +3,7 @@ import json
from typing import Any, Dict, List, Optional, Union
from services.auth import login_required
from services.core import get_my_followings, members
from services.core import get_my_followings, get_all_authors
from services.rediscache import redis
from services.schema import query
from validators.chat import Message, ChatPayload
@@ -17,7 +17,9 @@ async def get_unread_counter(chat_id: str, author_id: int) -> int:
# NOTE: not an API handler
async def load_messages(chat_id: str, limit: int = 5, offset: int = 0, ids: Optional[List[int]] = None) -> List[Message]:
async def load_messages(
chat_id: str, limit: int = 5, offset: int = 0, ids: Optional[List[int]] = None
) -> List[Message]:
"""load :limit messages for :chat_id with :offset"""
if ids is None:
ids = []
@@ -43,6 +45,7 @@ async def load_messages(chat_id: str, limit: int = 5, offset: int = 0, ids: Opti
messages += await load_messages(chat_id, offset, limit, replies)
except Exception:
import traceback
traceback.print_exc()
return messages
@@ -73,7 +76,7 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Uni
member_ids = c["members"].copy()
c["members"] = []
for member_id in member_ids:
for a in (await get_my_followings()):
for a in await get_my_followings():
a["online"] = a.get("id") in members_online
c["members"].append(a)
chats.append(c)
@@ -112,16 +115,16 @@ async def load_recipients(_, _info, limit=50, offset=0):
"""load possible chat participants"""
onliners = (await redis.execute("SMEMBERS", "authors-online")) or []
r = []
all_authors: List[ChatMember] = members
all_authors: List[ChatMember] = await get_all_authors()
my_followings = await get_my_followings()
if len(my_followings) < limit:
my_followings = my_followings + all_authors[0:limit-len(my_followings)]
my_followings = my_followings + all_authors[0 : limit - len(my_followings)]
for a in my_followings:
a["online"] = a["id"] in onliners
r.append(a)
# NOTE: maybe sort members here
print(f"[resolvers.load] loadRecipients found {len(r)} members")
return {"members": r, "error": None}