formatted
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
from typing import List
|
||||
from validators.inbox import Message
|
||||
|
||||
from services.auth import login_required
|
||||
from services.presence import notify_message
|
||||
from services.redis import redis
|
||||
from services.schema import mutation
|
||||
from validators.inbox import Message
|
||||
|
||||
|
||||
@mutation.field("createMessage")
|
||||
@@ -26,16 +27,15 @@ async def create_message(_, info, chat: str, body: str, reply_to=None):
|
||||
else:
|
||||
chat_dict = json.loads(chat_data)
|
||||
print(chat_dict)
|
||||
message_id = (
|
||||
await redis.execute("GET", f"chats/{chat_dict['id']}/next_message_id")
|
||||
) or 0
|
||||
message_id = int(message_id)
|
||||
message_id = await redis.execute("GET", f"chats/{chat_dict['id']}/next_message_id")
|
||||
message_id = int(message_id) if message_id else 0
|
||||
new_message: Message = {
|
||||
"chat": chat_dict["id"],
|
||||
"id": message_id,
|
||||
"author": author_id,
|
||||
"body": body,
|
||||
"createdAt": int(datetime.now(tz=timezone.utc).timestamp()),
|
||||
"updatedAt": None
|
||||
}
|
||||
if reply_to:
|
||||
new_message["replyTo"] = reply_to
|
||||
@@ -110,10 +110,10 @@ async def delete_message(_, info, chat_id: str, message_id: int):
|
||||
return {"error": "chat not exist"}
|
||||
chat = json.loads(chat)
|
||||
|
||||
message = await redis.execute("GET", f"chats/{chat_id}/messages/{str(message_id)}")
|
||||
if not message:
|
||||
message_data = await redis.execute("GET", f"chats/{chat_id}/messages/{str(message_id)}")
|
||||
if not message_data:
|
||||
return {"error": "message not exist"}
|
||||
message: Message = json.loads(message)
|
||||
message: Message = json.loads(message_data)
|
||||
if message["author"] != author_id:
|
||||
return {"error": "access denied"}
|
||||
|
||||
|
Reference in New Issue
Block a user