This commit is contained in:
parent
4ecdc08dfc
commit
cd2e4a08b3
|
@ -4,7 +4,7 @@ from typing import Dict, Union, List, Any
|
||||||
|
|
||||||
from resolvers.load import load_messages
|
from resolvers.load import load_messages
|
||||||
from services.auth import login_required
|
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.rediscache import redis
|
||||||
from services.schema import query
|
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"]
|
author_id = info.context["author_id"]
|
||||||
existed_chats = await redis.execute("SMEMBERS", f"/chats_by_author/{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:
|
if existed_chats:
|
||||||
for chat_id in list(json.loads(existed_chats))[offset : (offset + limit)]:
|
for chat_id in list(json.loads(existed_chats))[offset : (offset + limit)]:
|
||||||
members_ids = await redis.execute("GET", f"/chats/{chat_id}/members")
|
members_ids = await redis.execute("GET", f"/chats/{chat_id}/members")
|
||||||
for member_id in members_ids:
|
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["name"].startswith(text):
|
||||||
if author not in result:
|
if author not in result:
|
||||||
result.append(author)
|
result.append(author)
|
||||||
|
|
||||||
more_amount = limit - len(result)
|
more_amount = limit - len(result)
|
||||||
if more_amount > 0:
|
if more_amount > 0:
|
||||||
result += await get_network(author_id, more_amount)
|
result += authors[0:more_amount]
|
||||||
return {"members": list(result), "error": None}
|
return {"members": list(result), "error": None}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user