validators

This commit is contained in:
2023-10-14 09:38:12 +03:00
parent ee195d4ec7
commit d6e52d9465
9 changed files with 116 additions and 95 deletions

View File

@@ -26,9 +26,11 @@ 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 = (
await redis.execute("GET", f"chats/{chat_dict['id']}/next_message_id")
) or 0
message_id = int(message_id)
new_message = {
new_message: Message = {
"chat": chat_dict["id"],
"id": message_id,
"author": author_id,
@@ -41,9 +43,13 @@ async def create_message(_, info, chat: str, body: str, reply_to=None):
await redis.execute("SET", f"chats/{chat_dict['id']}", json.dumps(chat))
print(f"[inbox] creating message {new_message}")
await redis.execute(
"SET", f"chats/{chat_dict['id']}/messages/{message_id}", json.dumps(new_message)
"SET",
f"chats/{chat_dict['id']}/messages/{message_id}",
json.dumps(new_message),
)
await redis.execute(
"LPUSH", f"chats/{chat_dict['id']}/message_ids", str(message_id)
)
await redis.execute("LPUSH", f"chats/{chat_dict['id']}/message_ids", str(message_id))
await redis.execute(
"SET", f"chats/{chat_dict['id']}/next_message_id", str(message_id + 1)
)
@@ -147,13 +153,3 @@ async def mark_as_read(_, info, chat_id: str, messages: List[int]):
)
return {"error": None}
messages_resolvers = {
"Mutation": {
"markAsRead": mark_as_read,
"deleteMessage": delete_message,
"updateMessage": update_message,
"createMessage": create_message,
}
}