This commit is contained in:
parent
d25b406b60
commit
c6ad0414b0
|
@ -71,7 +71,7 @@ async def create_message(_, info, chat: str, body: str, reply_to=None):
|
||||||
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))
|
||||||
|
|
||||||
# Отправка уведомления о новом сообщении
|
# Отправка уведомления о новом сообщении
|
||||||
await notify_message(new_message, chat_dict["id"])
|
await notify_message(new_message, chat_dict["id"], "create")
|
||||||
|
|
||||||
return {"message": new_message, "error": None}
|
return {"message": new_message, "error": None}
|
||||||
|
|
||||||
|
@ -99,6 +99,7 @@ async def update_message(_, info, chat_id: str, message_id: int, body: str):
|
||||||
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))
|
||||||
|
|
||||||
# TODO: use presence service to notify about updated message
|
# TODO: use presence service to notify about updated message
|
||||||
|
await notify_message(message, chat_id, "update")
|
||||||
|
|
||||||
return {"message": message, "error": None}
|
return {"message": message, "error": None}
|
||||||
|
|
||||||
|
@ -128,6 +129,7 @@ async def delete_message(_, info, chat_id: str, message_id: int):
|
||||||
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))
|
||||||
|
|
||||||
# TODO: use presence service to notify about deleted message
|
# TODO: use presence service to notify about deleted message
|
||||||
|
await notify_message(message, chat_id, "delete")
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
@ -149,4 +151,7 @@ async def mark_as_read(_, info, chat_id: str, messages: List[int]):
|
||||||
for message_id in messages:
|
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))
|
||||||
|
|
||||||
|
# TODO: seen per author
|
||||||
|
# await notify_message(message, chat_id, "seen")
|
||||||
|
|
||||||
return {"error": None}
|
return {"error": None}
|
||||||
|
|
|
@ -4,11 +4,11 @@ from services.rediscache import redis
|
||||||
from validators.chat import Message
|
from validators.chat import Message
|
||||||
|
|
||||||
|
|
||||||
async def notify_message(message: Message, chat_id: str):
|
async def notify_message(message: Message, chat_id: str, action = "create"):
|
||||||
channel_name = f"chat:{chat_id}"
|
channel_name = f"chat:{chat_id}"
|
||||||
data = {"payload": message, "kind": "new_message"}
|
data = {"payload": message, "action": action}
|
||||||
try:
|
try:
|
||||||
await redis.publish(channel_name, json.dumps(data))
|
await redis.publish(channel_name, json.dumps(data))
|
||||||
print(f"[services.presence] notification was sent successfully {data}")
|
print(f"[services.presence] ok {data}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to publish to channel {channel_name}: {e}")
|
print(f"Failed to publish to channel {channel_name}: {e}")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user