This commit is contained in:
parent
c22b560bcf
commit
33b1323630
|
@ -39,13 +39,13 @@ type ChatResult {
|
||||||
type Mutation {
|
type Mutation {
|
||||||
# inbox
|
# inbox
|
||||||
createChat(title: String, members: [Int]!): ChatResult!
|
createChat(title: String, members: [Int]!): ChatResult!
|
||||||
updateChat(chat: ChatInput!): ChatResult!
|
updateChat(chat_id: ChatInput!): ChatResult!
|
||||||
deleteChat(chatId: String!): ChatResult!
|
deleteChat(chat_id: String!): ChatResult!
|
||||||
|
|
||||||
createMessage(chat: String!, body: String!, replyTo: Int): ChatResult!
|
createMessage(chat_id: String!, body: String!, reply_to: Int): ChatResult!
|
||||||
updateMessage(chatId: String!, id: Int!, body: String!): ChatResult!
|
updateMessage(chat_id: String!, message_id: Int!, body: String!): ChatResult!
|
||||||
deleteMessage(chatId: String!, id: Int!): ChatResult!
|
deleteMessage(chat_id: String!, message_id: Int!): ChatResult!
|
||||||
markAsRead(chatId: String!, ids: [Int]!): ChatResult!
|
markAsRead(chat_id: String!, message_id: Int!): ChatResult!
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ type Message {
|
||||||
body: String!
|
body: String!
|
||||||
created_at: Int!
|
created_at: Int!
|
||||||
id: Int!
|
id: Int!
|
||||||
replyTo: Int
|
reply_to: Int
|
||||||
updated_at: Int
|
updated_at: Int
|
||||||
seen: Boolean
|
seen: Boolean
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import json
|
import json
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from services.auth import login_required
|
from services.auth import login_required
|
||||||
from services.presence import notify_message
|
from services.presence import notify_message
|
||||||
|
@ -11,12 +10,12 @@ from validators.chat import Message
|
||||||
|
|
||||||
@mutation.field("createMessage")
|
@mutation.field("createMessage")
|
||||||
@login_required
|
@login_required
|
||||||
async def create_message(_, info, chat: 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"""
|
||||||
author_id = info.context["author_id"]
|
author_id = info.context["author_id"]
|
||||||
|
|
||||||
# Получение данных чата из Redis
|
# Получение данных чата из Redis
|
||||||
chat_data = await redis.execute("GET", f"chats/{chat}")
|
chat_data = await redis.execute("GET", f"chats/{chat_id}")
|
||||||
print(f"[resolvers.messages] debug chat data: {chat_data}")
|
print(f"[resolvers.messages] debug chat data: {chat_data}")
|
||||||
|
|
||||||
# Если данных чата нет, возвращаем ошибку
|
# Если данных чата нет, возвращаем ошибку
|
||||||
|
@ -139,7 +138,7 @@ async def delete_message(_, info, chat_id: str, message_id: int):
|
||||||
|
|
||||||
@mutation.field("markAsRead")
|
@mutation.field("markAsRead")
|
||||||
@login_required
|
@login_required
|
||||||
async def mark_as_read(_, info, chat_id: str, messages: List[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"]
|
||||||
|
|
||||||
chat_str = await redis.execute("GET", f"chats/{chat_id}")
|
chat_str = await redis.execute("GET", f"chats/{chat_id}")
|
||||||
|
@ -151,7 +150,6 @@ async def mark_as_read(_, info, chat_id: str, messages: List[int]):
|
||||||
if author_id not in members:
|
if author_id not in members:
|
||||||
return {"error": "access denied"}
|
return {"error": "access denied"}
|
||||||
|
|
||||||
for message_id in messages:
|
|
||||||
await redis.execute("LREM", f"chats/{chat_id}/unread/{author_id}", 0, str(message_id))
|
await redis.execute("LREM", f"chats/{chat_id}/unread/{author_id}", 0, str(message_id))
|
||||||
|
|
||||||
message_data = await redis.execute("GET", f"chats/{chat_id}/messages/{str(message_id)}")
|
message_data = await redis.execute("GET", f"chats/{chat_id}/messages/{str(message_id)}")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user