feat(achievement): support obtain achievements
This commit is contained in:
@@ -2,14 +2,20 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from app.log import logger
|
||||
from app.models.notification import NotificationDetails
|
||||
|
||||
from .base import RedisSubscriber
|
||||
|
||||
from pydantic import TypeAdapter
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.router.chat.server import ChatServer
|
||||
from app.router.notification.server import ChatServer
|
||||
|
||||
|
||||
JOIN_CHANNEL = "chat:room:joined"
|
||||
EXIT_CHANNEL = "chat:room:left"
|
||||
ON_NOTIFICATION = "chat:notification"
|
||||
|
||||
|
||||
class ChatSubscriber(RedisSubscriber):
|
||||
@@ -23,6 +29,8 @@ class ChatSubscriber(RedisSubscriber):
|
||||
self.add_handler(JOIN_CHANNEL, self.on_join_room)
|
||||
await self.subscribe(EXIT_CHANNEL)
|
||||
self.add_handler(EXIT_CHANNEL, self.on_leave_room)
|
||||
await self.subscribe(ON_NOTIFICATION)
|
||||
self.add_handler(ON_NOTIFICATION, self.on_notification)
|
||||
self.start()
|
||||
|
||||
async def on_join_room(self, c: str, s: str):
|
||||
@@ -36,3 +44,16 @@ class ChatSubscriber(RedisSubscriber):
|
||||
if self.chat_server is None:
|
||||
return
|
||||
await self.chat_server.leave_room_channel(int(channel_id), int(user_id))
|
||||
|
||||
async def on_notification(self, c: str, s: str):
|
||||
try:
|
||||
detail = TypeAdapter(NotificationDetails).validate_json(s)
|
||||
except ValueError:
|
||||
logger.exception("")
|
||||
return
|
||||
except Exception:
|
||||
logger.exception("Failed to parse notification detail")
|
||||
return
|
||||
if self.chat_server is None:
|
||||
return
|
||||
await self.chat_server.new_private_notification(detail)
|
||||
|
||||
Reference in New Issue
Block a user