Notifications accept.
This commit is contained in:
parent
c3c94461c2
commit
578c182f27
@ -1,9 +1,17 @@
|
|||||||
from snek.system.service import BaseService
|
from snek.system.service import BaseService
|
||||||
|
from snek.system.model import now
|
||||||
|
|
||||||
class NotificationService(BaseService):
|
class NotificationService(BaseService):
|
||||||
mapper_name = "notification"
|
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):
|
async def create(self, object_uid, object_type, user_uid, message):
|
||||||
model = await self.new()
|
model = await self.new()
|
||||||
model["object_uid"] = object_uid
|
model["object_uid"] = object_uid
|
||||||
|
@ -39,6 +39,11 @@ class RPCView(BaseView):
|
|||||||
def is_logged_in(self):
|
def is_logged_in(self):
|
||||||
return self.view.session.get("logged_in", False)
|
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):
|
async def login(self, username, password):
|
||||||
success = await self.services.user.validate_login(username, password)
|
success = await self.services.user.validate_login(username, password)
|
||||||
if not success:
|
if not success:
|
||||||
|
@ -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(
|
messages = [await self.app.services.channel_message.to_extended_dict(message) for message in await self.app.services.channel_message.offset(
|
||||||
channel["uid"]
|
channel["uid"]
|
||||||
)]
|
)]
|
||||||
|
for message in messages:
|
||||||
|
await self.app.services.notification.mark_as_read(self.session.get("uid"),message["uid"])
|
||||||
|
|
||||||
channels = []
|
channels = []
|
||||||
async for subscribed_channel in self.app.services.channel_member.find(user_uid=self.session.get("uid"), deleted_at=None, is_banned=False):
|
async for subscribed_channel in self.app.services.channel_member.find(user_uid=self.session.get("uid"), deleted_at=None, is_banned=False):
|
||||||
item = {}
|
item = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user