resolvers-renamed
Some checks failed
deploy / deploy (push) Failing after 1m7s

This commit is contained in:
2023-11-28 11:33:50 +03:00
parent 493f6106ab
commit 15139249f1
8 changed files with 34 additions and 34 deletions

View File

@@ -6,7 +6,7 @@ from resolvers.messages import (
update_message,
mark_as_read,
)
from resolvers.search import search_recipients
from resolvers.search import search_recipients, search_messages
__all__ = [
# inbox
@@ -21,4 +21,5 @@ __all__ = [
"mark_as_read",
"load_recipients",
"search_recipients",
"search_messages",
]

View File

@@ -9,7 +9,7 @@ from models.chat import Chat, ChatUpdate
from services.presence import notify_chat
@mutation.field("updateChat")
@mutation.field("update_chat")
@login_required
async def update_chat(_, info, chat_new: ChatUpdate):
"""
@@ -45,7 +45,7 @@ async def update_chat(_, info, chat_new: ChatUpdate):
return {"error": None, "chat": chat}
@mutation.field("createChat")
@mutation.field("create_chat")
@login_required
async def create_chat(_, info, title="", members=None):
if members is None:
@@ -92,7 +92,7 @@ async def create_chat(_, info, title="", members=None):
return {"error": None, "chat": chat}
@mutation.field("deleteChat")
@mutation.field("delete_chat")
@login_required
async def delete_chat(_, info, chat_id: str):
author_id = info.context["author_id"]

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, get_all_authors
from services.core import get_my_followed, get_all_authors
from services.rediscache import redis
from services.schema import query
from models.chat import Message, ChatPayload
@@ -19,7 +19,7 @@ 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|None]:
) -> List[Message | None]:
"""load :limit messages for :chat_id with :offset"""
messages = []
try:
@@ -48,7 +48,7 @@ async def load_messages(
return messages
@query.field("loadChats")
@query.field("load_chats")
@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"""
@@ -84,7 +84,7 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Uni
return {"chats": chats, "error": None}
@query.field("loadMessagesBy")
@query.field("load_messages_by")
@login_required
async def load_messages_by(_, info, by, limit: int = 10, offset: int = 0):
"""load :limit messages of :chat_id with :offset"""
@@ -111,13 +111,13 @@ async def load_messages_by(_, info, by, limit: int = 10, offset: int = 0):
return {"error": "Cannot access messages of this chat"}
@query.field("loadRecipients")
@query.field("load_recipients")
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] = await get_all_authors()
my_followings: List[ChatMember] = await get_my_followings()
my_followings: List[ChatMember] = await get_my_followed()
if all_authors:
if len(my_followings) < limit:
my_followings = my_followings + all_authors[0 : limit - len(my_followings)]

View File

@@ -8,7 +8,7 @@ from services.schema import mutation
from models.chat import Message
@mutation.field("createMessage")
@mutation.field("create_message")
@login_required
async def create_message(_, info, chat_id: str, body: str, reply_to=None):
"""Создание сообщения с телом :body для чата :chat_id с возможным ответом на :reply_to"""
@@ -76,7 +76,7 @@ async def create_message(_, info, chat_id: str, body: str, reply_to=None):
return {"message": new_message, "error": None}
@mutation.field("updateMessage")
@mutation.field("update_message")
@login_required
async def update_message(_, info, message):
author_id = info.context["author_id"]
@@ -144,7 +144,7 @@ async def delete_message(_, info, chat_id: str, message_id: int):
return {}
@mutation.field("markAsRead")
@mutation.field("mark_as_read")
@login_required
async def mark_as_read(_, info, chat_id: str, message_id: int):
author_id = info.context["author_id"]

View File

@@ -9,7 +9,7 @@ from services.rediscache import redis
from services.schema import query
@query.field("searchRecipients")
@query.field("search_recipients")
@login_required
async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0):
result = []
@@ -36,9 +36,9 @@ async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0
return {"members": list(result), "error": None}
@query.field("searchMessages")
@query.field("search_messages")
@login_required
async def search_in_chats(
async def search_messages(
_, 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"]