Notifications accept.

This commit is contained in:
retoor 2025-03-05 17:51:25 +01:00
parent c3c94461c2
commit 578c182f27
3 changed files with 17 additions and 1 deletions

View File

@ -1,9 +1,17 @@
from snek.system.service import BaseService
from snek.system.model import now
class NotificationService(BaseService):
mapper_name = "notification"
async def mark_as_read(self, user_uid, channel_message_uid):
model = await self.get(user_uid, object_uid=channel_message_uid)
model['read_at'] = now()
await self.save(model)
async def get_unread_stats(self,user_uid):
records = await self.query("SELECT object_type, COUNT(*) as count FROM notification WHERE user_uid=:user_uid AND read_at IS NULL GROUP BY object_type",dict(user_uid=user_uid))
async def create(self, object_uid, object_type, user_uid, message):
model = await self.new()
model["object_uid"] = object_uid

View File

@ -39,6 +39,11 @@ class RPCView(BaseView):
def is_logged_in(self):
return self.view.session.get("logged_in", False)
async def mark_as_read(self, message_uid):
self._require_login()
await self.services.notification.mark_as_read(self.user_uid, message_uid)
return True
async def login(self, username, password):
success = await self.services.user.validate_login(username, password)
if not success:

View File

@ -46,6 +46,9 @@ class WebView(BaseView):
messages = [await self.app.services.channel_message.to_extended_dict(message) for message in await self.app.services.channel_message.offset(
channel["uid"]
)]
for message in messages:
await self.app.services.notification.mark_as_read(self.session.get("uid"),message["uid"])
channels = []
async for subscribed_channel in self.app.services.channel_member.find(user_uid=self.session.get("uid"), deleted_at=None, is_banned=False):
item = {}