inbox/services/presence.py
Untone 97aed41143
All checks were successful
deploy / deploy (push) Successful in 47s
typo-fix
2024-04-19 10:48:51 +03:00

27 lines
880 B
Python

import json
from services.logger import root_logger as logger
from models.chat import ChatUpdate, Message
from services.rediscache import redis
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))
logger.info(f"ok {data}")
except Exception as e:
logger.error(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))
logger.info(f"ok {data}")
except Exception as e:
logger.error(f"Failed to publish to channel {channel_name}: {e}")