format+fix-2
All checks were successful
deploy / deploy (push) Successful in 1m17s

This commit is contained in:
Untone 2023-11-14 21:31:02 +03:00
parent 4ecdc08dfc
commit cd2e4a08b3

View File

@ -4,7 +4,7 @@ from typing import Dict, Union, List, Any
from resolvers.load import load_messages
from services.auth import login_required
from services.core import get_network
from services.core import get_all_authors
from services.rediscache import redis
from services.schema import query
@ -18,18 +18,21 @@ async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0
author_id = info.context["author_id"]
existed_chats = await redis.execute("SMEMBERS", f"/chats_by_author/{author_id}")
authors = await get_all_authors()
members = {a["id"]: a for a in authors}
if existed_chats:
for chat_id in list(json.loads(existed_chats))[offset : (offset + limit)]:
members_ids = await redis.execute("GET", f"/chats/{chat_id}/members")
for member_id in members_ids:
for author in (await get_network(member_id), 1):
author = members.get(member_id)
if author:
if author["name"].startswith(text):
if author not in result:
result.append(author)
more_amount = limit - len(result)
if more_amount > 0:
result += await get_network(author_id, more_amount)
result += authors[0:more_amount]
return {"members": list(result), "error": None}