diff --git a/inbox.graphql b/inbox.graphql index 91ac806..1c3a204 100644 --- a/inbox.graphql +++ b/inbox.graphql @@ -41,15 +41,14 @@ type ChatResult { type Mutation { # inbox - createChat(title: String, members: [Int]!): ChatResult! - updateChat(chat: ChatInput!): ChatResult! - deleteChat(chat_id: String!): ChatResult! - - createMessage(chat_id: String!, body: String!, reply_to: Int): ChatResult! - updateMessage(message: MessageInput!): ChatResult! - deleteMessage(chat_id: String!, message_id: Int!): ChatResult! - markAsRead(chat_id: String!, message_id: Int!): ChatResult! + create_chat(title: String, members: [Int]!): ChatResult! + update_chat(chat: ChatInput!): ChatResult! + delete_chat(chat_id: String!): ChatResult! + create_message(chat_id: String!, body: String!, reply_to: Int): ChatResult! + update_message(message: MessageInput!): ChatResult! + delete_message(chat_id: String!, message_id: Int!): ChatResult! + mark_as_read(chat_id: String!, message_id: Int!): ChatResult! } input MessagesBy { @@ -63,11 +62,11 @@ input MessagesBy { type Query { # inbox - loadChats(limit: Int, offset: Int): ChatResult! # your chats - loadMessagesBy(by: MessagesBy!, limit: Int, offset: Int): ChatResult! - loadRecipients(limit: Int, offset: Int): ChatResult! - searchRecipients(query: String!, limit: Int, offset: Int): ChatResult! - searchMessages(by: MessagesBy!, limit: Int, offset: Int): ChatResult! + load_chats(limit: Int, offset: Int): ChatResult! # your chats + load_messages_by(by: MessagesBy!, limit: Int, offset: Int): ChatResult! + load_recipients(limit: Int, offset: Int): ChatResult! + search_recipients(query: String!, limit: Int, offset: Int): ChatResult! + search_messages(by: MessagesBy!, limit: Int, offset: Int): ChatResult! } type Message { diff --git a/resolvers/__init__.py b/resolvers/__init__.py index 6c70e55..9183caf 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -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", ] diff --git a/resolvers/chats.py b/resolvers/chats.py index 74e1e98..99cd828 100644 --- a/resolvers/chats.py +++ b/resolvers/chats.py @@ -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"] diff --git a/resolvers/load.py b/resolvers/load.py index 427ad14..78facee 100644 --- a/resolvers/load.py +++ b/resolvers/load.py @@ -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)] diff --git a/resolvers/messages.py b/resolvers/messages.py index c2d6bad..e2542e1 100644 --- a/resolvers/messages.py +++ b/resolvers/messages.py @@ -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"] diff --git a/resolvers/search.py b/resolvers/search.py index 1ca877a..87553b3 100644 --- a/resolvers/search.py +++ b/resolvers/search.py @@ -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"] diff --git a/services/auth.py b/services/auth.py index 873d116..eb7a820 100644 --- a/services/auth.py +++ b/services/auth.py @@ -8,8 +8,8 @@ async def check_auth(req): headers = {"Authorization": token, "Content-Type": "application/json"} # "Bearer " + removed print(f"[services.auth] checking auth token: {token}") - query_name = "getSession" if "v2." in AUTH_URL else "session" - query_type = "mutation" if "v2." in AUTH_URL else "query" + query_name = "session" + query_type = "query" operation = "GetUserId" gql = { diff --git a/services/core.py b/services/core.py index b59ca5a..8737739 100644 --- a/services/core.py +++ b/services/core.py @@ -34,10 +34,10 @@ async def get_all_authors() -> List[ChatMember]: return [] -async def get_my_followings() -> List[ChatMember]: - query_name = "loadMySubscriptions" +async def get_my_followed() -> List[ChatMember]: + query_name = "get_my_followed" query_type = "query" - operation = "LoadMySubscriptions" + operation = "GetMyFollowed" query_fields = "id slug pic name" gql = {