2023-10-05 18:46:18 +00:00
|
|
|
import json
|
|
|
|
from services.redis import redis
|
|
|
|
|
|
|
|
|
2023-10-16 15:25:15 +00:00
|
|
|
async def notify_reaction(reaction):
|
2023-10-19 14:42:42 +00:00
|
|
|
channel_name = "reaction"
|
2023-10-16 14:51:08 +00:00
|
|
|
data = {
|
|
|
|
"payload": reaction,
|
2023-10-19 14:42:42 +00:00
|
|
|
"action": "create"
|
2023-10-16 14:51:08 +00:00
|
|
|
}
|
2023-10-05 18:46:18 +00:00
|
|
|
try:
|
|
|
|
await redis.publish(channel_name, json.dumps(data))
|
|
|
|
except Exception as e:
|
|
|
|
print(f"Failed to publish to channel {channel_name}: {e}")
|
|
|
|
|
|
|
|
|
2023-10-16 15:25:15 +00:00
|
|
|
async def notify_shout(shout):
|
2023-10-19 14:42:42 +00:00
|
|
|
channel_name = "shout"
|
2023-10-16 14:51:08 +00:00
|
|
|
data = {
|
2023-10-19 14:42:42 +00:00
|
|
|
"payload": shout,
|
|
|
|
"action": "create"
|
2023-10-16 14:51:08 +00:00
|
|
|
}
|
2023-10-05 18:46:18 +00:00
|
|
|
try:
|
|
|
|
await redis.publish(channel_name, json.dumps(data))
|
|
|
|
except Exception as e:
|
|
|
|
print(f"Failed to publish to channel {channel_name}: {e}")
|
|
|
|
|
|
|
|
|
2023-10-16 15:25:15 +00:00
|
|
|
async def notify_follower(follower: dict, author_id: int):
|
|
|
|
fields = follower.keys()
|
|
|
|
for k in fields:
|
|
|
|
if k not in ["id", "name", "slug", "userpic"]:
|
|
|
|
del follower[k]
|
2023-10-19 14:42:42 +00:00
|
|
|
channel_name = f"follower:{author_id}"
|
2023-10-05 18:46:18 +00:00
|
|
|
data = {
|
2023-10-16 14:51:08 +00:00
|
|
|
"payload": follower,
|
2023-10-19 14:42:42 +00:00
|
|
|
"action": "follow",
|
2023-10-05 18:46:18 +00:00
|
|
|
}
|
|
|
|
try:
|
|
|
|
await redis.publish(channel_name, json.dumps(data))
|
|
|
|
except Exception as e:
|
|
|
|
print(f"Failed to publish to channel {channel_name}: {e}")
|