validators
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user