notify-message-chat
All checks were successful
deploy / deploy (push) Successful in 1m17s

This commit is contained in:
2023-11-16 17:52:39 +03:00
parent 1b94353850
commit 871f7e1d69
3 changed files with 50 additions and 27 deletions

View File

@@ -1,14 +1,24 @@
import json
from services.rediscache import redis
from validators.chat import Message
from validators.chat import Message, ChatUpdate
async def notify_message(message: Message, chat_id: str, action="create"):
channel_name = f"chat:{chat_id}"
async def notify_message(message: Message, action="create"):
channel_name = f"message:{message["chat"]}"
data = {"payload": message, "action": action}
try:
await redis.publish(channel_name, json.dumps(data))
print(f"[services.presence] ok {data}")
except Exception as e:
print(f"Failed to publish to channel {channel_name}: {e}")
async def notify_chat(chat: ChatUpdate, member_id, action="create"):
channel_name = f"chat:{member_id}"
data = {"payload": chat, "action": action}
try:
await redis.publish(channel_name, json.dumps(data))
print(f"[services.presence] ok {data}")
except Exception as e:
print(f"Failed to publish to channel {channel_name}: {e}")