validators
This commit is contained in:
@@ -12,7 +12,9 @@ from services.schema import query
|
||||
@login_required
|
||||
async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0):
|
||||
result = []
|
||||
|
||||
# TODO: maybe redis scan?
|
||||
|
||||
author_id = info.context["author_id"]
|
||||
talk_before = await redis.execute("GET", f"/chats_by_author/{author_id}")
|
||||
if talk_before:
|
||||
@@ -34,9 +36,13 @@ async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0
|
||||
|
||||
@query.field("searchMessages")
|
||||
@login_required
|
||||
async def search_in_chats(_, info, by: Dict[str, Union[str, int]], limit: int, offset: int) -> Dict[str, Union[List[Dict[str, Any]], None]]:
|
||||
async def search_in_chats(
|
||||
_, info, by: Dict[str, Union[str, int]], limit: int, offset: int
|
||||
) -> Dict[str, Union[List[Dict[str, Any]], None]]:
|
||||
author_id = info.context["author_id"]
|
||||
lookup_chats = set((await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")) or [])
|
||||
lookup_chats = set(
|
||||
(await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")) or []
|
||||
)
|
||||
messages_set = set([])
|
||||
|
||||
by_member = by.get("author")
|
||||
@@ -59,20 +65,16 @@ async def search_in_chats(_, info, by: Dict[str, Union[str, int]], limit: int, o
|
||||
if body_like:
|
||||
mmm = list(filter(lambda mx: body_like in mx["body"], mmm))
|
||||
if days_ago:
|
||||
mmm = list(filter(
|
||||
lambda msg: int(datetime.now(tz=timezone.utc)) - int(msg["createdAt"])
|
||||
< timedelta(days=days_ago),
|
||||
mmm,
|
||||
))
|
||||
mmm = list(
|
||||
filter(
|
||||
lambda msg: int(datetime.now(tz=timezone.utc))
|
||||
- int(msg["createdAt"])
|
||||
< timedelta(days=days_ago),
|
||||
mmm,
|
||||
)
|
||||
)
|
||||
|
||||
messages_set.union(set(mmm))
|
||||
|
||||
messages_sorted = sorted(list(messages_set))
|
||||
return {"messages": messages_sorted, "error": None}
|
||||
|
||||
search_resolvers = {
|
||||
"Query": {
|
||||
"searchMessages": search_in_chats,
|
||||
"searchRecipients": search_recipients,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user