This commit is contained in:
parent
493f6106ab
commit
15139249f1
|
@ -41,15 +41,14 @@ type ChatResult {
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
# inbox
|
# inbox
|
||||||
createChat(title: String, members: [Int]!): ChatResult!
|
create_chat(title: String, members: [Int]!): ChatResult!
|
||||||
updateChat(chat: ChatInput!): ChatResult!
|
update_chat(chat: ChatInput!): ChatResult!
|
||||||
deleteChat(chat_id: String!): ChatResult!
|
delete_chat(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_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 {
|
input MessagesBy {
|
||||||
|
@ -63,11 +62,11 @@ input MessagesBy {
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
# inbox
|
# inbox
|
||||||
loadChats(limit: Int, offset: Int): ChatResult! # your chats
|
load_chats(limit: Int, offset: Int): ChatResult! # your chats
|
||||||
loadMessagesBy(by: MessagesBy!, limit: Int, offset: Int): ChatResult!
|
load_messages_by(by: MessagesBy!, limit: Int, offset: Int): ChatResult!
|
||||||
loadRecipients(limit: Int, offset: Int): ChatResult!
|
load_recipients(limit: Int, offset: Int): ChatResult!
|
||||||
searchRecipients(query: String!, limit: Int, offset: Int): ChatResult!
|
search_recipients(query: String!, limit: Int, offset: Int): ChatResult!
|
||||||
searchMessages(by: MessagesBy!, limit: Int, offset: Int): ChatResult!
|
search_messages(by: MessagesBy!, limit: Int, offset: Int): ChatResult!
|
||||||
}
|
}
|
||||||
|
|
||||||
type Message {
|
type Message {
|
||||||
|
|
|
@ -6,7 +6,7 @@ from resolvers.messages import (
|
||||||
update_message,
|
update_message,
|
||||||
mark_as_read,
|
mark_as_read,
|
||||||
)
|
)
|
||||||
from resolvers.search import search_recipients
|
from resolvers.search import search_recipients, search_messages
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
# inbox
|
# inbox
|
||||||
|
@ -21,4 +21,5 @@ __all__ = [
|
||||||
"mark_as_read",
|
"mark_as_read",
|
||||||
"load_recipients",
|
"load_recipients",
|
||||||
"search_recipients",
|
"search_recipients",
|
||||||
|
"search_messages",
|
||||||
]
|
]
|
||||||
|
|
|
@ -9,7 +9,7 @@ from models.chat import Chat, ChatUpdate
|
||||||
from services.presence import notify_chat
|
from services.presence import notify_chat
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("updateChat")
|
@mutation.field("update_chat")
|
||||||
@login_required
|
@login_required
|
||||||
async def update_chat(_, info, chat_new: ChatUpdate):
|
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}
|
return {"error": None, "chat": chat}
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("createChat")
|
@mutation.field("create_chat")
|
||||||
@login_required
|
@login_required
|
||||||
async def create_chat(_, info, title="", members=None):
|
async def create_chat(_, info, title="", members=None):
|
||||||
if members is None:
|
if members is None:
|
||||||
|
@ -92,7 +92,7 @@ async def create_chat(_, info, title="", members=None):
|
||||||
return {"error": None, "chat": chat}
|
return {"error": None, "chat": chat}
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("deleteChat")
|
@mutation.field("delete_chat")
|
||||||
@login_required
|
@login_required
|
||||||
async def delete_chat(_, info, chat_id: str):
|
async def delete_chat(_, info, chat_id: str):
|
||||||
author_id = info.context["author_id"]
|
author_id = info.context["author_id"]
|
||||||
|
|
|
@ -3,7 +3,7 @@ import json
|
||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Any, Dict, List, Optional, Union
|
||||||
|
|
||||||
from services.auth import login_required
|
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.rediscache import redis
|
||||||
from services.schema import query
|
from services.schema import query
|
||||||
from models.chat import Message, ChatPayload
|
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
|
# NOTE: not an API handler
|
||||||
async def load_messages(
|
async def load_messages(
|
||||||
chat_id: str, limit: int = 5, offset: int = 0, ids: Optional[List[int]] = None
|
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"""
|
"""load :limit messages for :chat_id with :offset"""
|
||||||
messages = []
|
messages = []
|
||||||
try:
|
try:
|
||||||
|
@ -48,7 +48,7 @@ async def load_messages(
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
|
||||||
@query.field("loadChats")
|
@query.field("load_chats")
|
||||||
@login_required
|
@login_required
|
||||||
async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Union[List[Dict[str, Any]], None]]:
|
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"""
|
"""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}
|
return {"chats": chats, "error": None}
|
||||||
|
|
||||||
|
|
||||||
@query.field("loadMessagesBy")
|
@query.field("load_messages_by")
|
||||||
@login_required
|
@login_required
|
||||||
async def load_messages_by(_, info, by, limit: int = 10, offset: int = 0):
|
async def load_messages_by(_, info, by, limit: int = 10, offset: int = 0):
|
||||||
"""load :limit messages of :chat_id with :offset"""
|
"""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"}
|
return {"error": "Cannot access messages of this chat"}
|
||||||
|
|
||||||
|
|
||||||
@query.field("loadRecipients")
|
@query.field("load_recipients")
|
||||||
async def load_recipients(_, _info, limit=50, offset=0):
|
async def load_recipients(_, _info, limit=50, offset=0):
|
||||||
"""load possible chat participants"""
|
"""load possible chat participants"""
|
||||||
onliners = (await redis.execute("SMEMBERS", "authors-online")) or []
|
onliners = (await redis.execute("SMEMBERS", "authors-online")) or []
|
||||||
r = []
|
r = []
|
||||||
all_authors: List[ChatMember] = await get_all_authors()
|
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 all_authors:
|
||||||
if len(my_followings) < limit:
|
if len(my_followings) < limit:
|
||||||
my_followings = my_followings + all_authors[0 : limit - len(my_followings)]
|
my_followings = my_followings + all_authors[0 : limit - len(my_followings)]
|
||||||
|
|
|
@ -8,7 +8,7 @@ from services.schema import mutation
|
||||||
from models.chat import Message
|
from models.chat import Message
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("createMessage")
|
@mutation.field("create_message")
|
||||||
@login_required
|
@login_required
|
||||||
async def create_message(_, info, chat_id: str, body: str, reply_to=None):
|
async def create_message(_, info, chat_id: str, body: str, reply_to=None):
|
||||||
"""Создание сообщения с телом :body для чата :chat_id с возможным ответом на :reply_to"""
|
"""Создание сообщения с телом :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}
|
return {"message": new_message, "error": None}
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("updateMessage")
|
@mutation.field("update_message")
|
||||||
@login_required
|
@login_required
|
||||||
async def update_message(_, info, message):
|
async def update_message(_, info, message):
|
||||||
author_id = info.context["author_id"]
|
author_id = info.context["author_id"]
|
||||||
|
@ -144,7 +144,7 @@ async def delete_message(_, info, chat_id: str, message_id: int):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("markAsRead")
|
@mutation.field("mark_as_read")
|
||||||
@login_required
|
@login_required
|
||||||
async def mark_as_read(_, info, chat_id: str, message_id: int):
|
async def mark_as_read(_, info, chat_id: str, message_id: int):
|
||||||
author_id = info.context["author_id"]
|
author_id = info.context["author_id"]
|
||||||
|
|
|
@ -9,7 +9,7 @@ from services.rediscache import redis
|
||||||
from services.schema import query
|
from services.schema import query
|
||||||
|
|
||||||
|
|
||||||
@query.field("searchRecipients")
|
@query.field("search_recipients")
|
||||||
@login_required
|
@login_required
|
||||||
async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0):
|
async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0):
|
||||||
result = []
|
result = []
|
||||||
|
@ -36,9 +36,9 @@ async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0
|
||||||
return {"members": list(result), "error": None}
|
return {"members": list(result), "error": None}
|
||||||
|
|
||||||
|
|
||||||
@query.field("searchMessages")
|
@query.field("search_messages")
|
||||||
@login_required
|
@login_required
|
||||||
async def search_in_chats(
|
async def search_messages(
|
||||||
_, info, by: Dict[str, Union[str, int]], limit: int, offset: int
|
_, info, by: Dict[str, Union[str, int]], limit: int, offset: int
|
||||||
) -> Dict[str, Union[List[Dict[str, Any]], None]]:
|
) -> Dict[str, Union[List[Dict[str, Any]], None]]:
|
||||||
author_id = info.context["author_id"]
|
author_id = info.context["author_id"]
|
||||||
|
|
|
@ -8,8 +8,8 @@ async def check_auth(req):
|
||||||
headers = {"Authorization": token, "Content-Type": "application/json"} # "Bearer " + removed
|
headers = {"Authorization": token, "Content-Type": "application/json"} # "Bearer " + removed
|
||||||
print(f"[services.auth] checking auth token: {token}")
|
print(f"[services.auth] checking auth token: {token}")
|
||||||
|
|
||||||
query_name = "getSession" if "v2." in AUTH_URL else "session"
|
query_name = "session"
|
||||||
query_type = "mutation" if "v2." in AUTH_URL else "query"
|
query_type = "query"
|
||||||
operation = "GetUserId"
|
operation = "GetUserId"
|
||||||
|
|
||||||
gql = {
|
gql = {
|
||||||
|
|
|
@ -34,10 +34,10 @@ async def get_all_authors() -> List[ChatMember]:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
async def get_my_followings() -> List[ChatMember]:
|
async def get_my_followed() -> List[ChatMember]:
|
||||||
query_name = "loadMySubscriptions"
|
query_name = "get_my_followed"
|
||||||
query_type = "query"
|
query_type = "query"
|
||||||
operation = "LoadMySubscriptions"
|
operation = "GetMyFollowed"
|
||||||
query_fields = "id slug pic name"
|
query_fields = "id slug pic name"
|
||||||
|
|
||||||
gql = {
|
gql = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user