From 823b3c56c12684e818ffa4cdc78583fddf975cc4 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 16 Oct 2023 17:51:08 +0300 Subject: [PATCH] presence service interface fix --- services/presence.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/services/presence.py b/services/presence.py index d378c859..31c63f7a 100644 --- a/services/presence.py +++ b/services/presence.py @@ -1,12 +1,16 @@ import json from orm.reaction import Reaction from orm.shout import Shout +from orm.user import Author from services.redis import redis async def notify_reaction(reaction: Reaction): - channel_name = f"new_reaction" - data = {**reaction, "kind": f"new_reaction{reaction.kind}"} + channel_name = "new_reaction" + data = { + "payload": reaction, + "kind": f"new_reaction{reaction.kind}" + } try: await redis.publish(channel_name, json.dumps(data)) except Exception as e: @@ -14,19 +18,21 @@ async def notify_reaction(reaction: Reaction): async def notify_shout(shout: Shout): - channel_name = f"new_shout" - data = {**shout, "kind": "new_shout"} + channel_name = "new_shout" + data = { + "payload": shout, + "kind": "new_shout" + } try: await redis.publish(channel_name, json.dumps(data)) except Exception as e: print(f"Failed to publish to channel {channel_name}: {e}") -async def notify_follower(follower_id: int, author_id: int): - channel_name = f"new_follower" +async def notify_follower(follower: Author, author_id: int): + channel_name = f"followers:{author_id}" data = { - "follower_id": follower_id, - "author_id": author_id, + "payload": follower, "kind": "new_follower", } try: