inspected
This commit is contained in:
@@ -4,9 +4,9 @@ from typing import List
|
||||
|
||||
from services.auth import login_required
|
||||
from services.presence import notify_message
|
||||
from services.redis import redis
|
||||
from services.rediscache import redis
|
||||
from services.schema import mutation
|
||||
from validators.inbox import Message
|
||||
from validators.chat import Message
|
||||
|
||||
|
||||
@mutation.field("createMessage")
|
||||
@@ -35,7 +35,7 @@ async def create_message(_, info, chat: str, body: str, reply_to=None):
|
||||
"author": author_id,
|
||||
"body": body,
|
||||
"createdAt": int(datetime.now(tz=timezone.utc).timestamp()),
|
||||
"updatedAt": None
|
||||
"updatedAt": None,
|
||||
}
|
||||
if reply_to:
|
||||
new_message["replyTo"] = reply_to
|
||||
@@ -47,18 +47,12 @@ async def create_message(_, info, chat: str, body: str, reply_to=None):
|
||||
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(
|
||||
"SET", f"chats/{chat_dict['id']}/next_message_id", str(message_id + 1)
|
||||
)
|
||||
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))
|
||||
|
||||
members = chat_dict["members"]
|
||||
for member_id in members:
|
||||
await redis.execute(
|
||||
"LPUSH", f"chats/{chat_dict['id']}/unread/{member_id}", str(message_id)
|
||||
)
|
||||
await redis.execute("LPUSH", f"chats/{chat_dict['id']}/unread/{member_id}", str(message_id))
|
||||
|
||||
# result = FollowingResult("NEW", "chat", new_message)
|
||||
# await FollowingManager.push("chat", result)
|
||||
@@ -89,9 +83,7 @@ async def update_message(_, info, chat_id: str, message_id: int, body: str):
|
||||
message["body"] = body
|
||||
message["updatedAt"] = int(datetime.now(tz=timezone.utc).timestamp())
|
||||
|
||||
await redis.execute(
|
||||
"SET", f"chats/{chat_id}/messages/{message_id}", json.dumps(message)
|
||||
)
|
||||
await redis.execute("SET", f"chats/{chat_id}/messages/{message_id}", json.dumps(message))
|
||||
|
||||
# result = FollowingResult("UPDATE", "chat", new_message)
|
||||
# await FollowingManager.push("chat", result)
|
||||
@@ -122,9 +114,7 @@ async def delete_message(_, info, chat_id: str, message_id: int):
|
||||
|
||||
members = chat["members"]
|
||||
for member_id in members:
|
||||
await redis.execute(
|
||||
"LREM", f"chats/{chat_id}/unread/{member_id}", 0, str(message_id)
|
||||
)
|
||||
await redis.execute("LREM", f"chats/{chat_id}/unread/{member_id}", 0, str(message_id))
|
||||
|
||||
# result = FollowingResult("DELETED", "chat", message)
|
||||
# await FollowingManager.push(result)
|
||||
@@ -148,8 +138,6 @@ async def mark_as_read(_, info, chat_id: str, messages: List[int]):
|
||||
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))
|
||||
|
||||
return {"error": None}
|
||||
|
Reference in New Issue
Block a user