inbox/services/presence.py
Untone c53b7a4c6c
All checks were successful
deploy / deploy (push) Successful in 1m13s
author-id-fix
2023-11-28 12:05:39 +03:00

25 lines
843 B
Python

import json
from services.rediscache import redis
from models.chat import Message, ChatUpdate
async def notify_message(message: Message, action="create"):
channel_name = f"message:{message['chat_id']}"
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: int, 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}")