This commit is contained in:
parent
f4d4fd26d4
commit
a442119495
|
@ -28,6 +28,7 @@ class Notification:
|
|||
class NotificationsQueryResult:
|
||||
notifications: list[Notification]
|
||||
unread: int
|
||||
total: int
|
||||
|
||||
|
||||
@strawberry.type
|
||||
|
@ -47,7 +48,6 @@ def notification_seen_by_viewer(viewer_id, notification_id, session):
|
|||
.filter(NotificationSeen.viewer == viewer_id, NotificationSeen.notification == notification_id)
|
||||
.first()
|
||||
)
|
||||
|
||||
return seen is not None
|
||||
|
||||
|
||||
|
@ -56,13 +56,12 @@ class Query:
|
|||
@strawberry.field
|
||||
@login_required
|
||||
async def load_notifications(self, info, limit: int = 50, offset: int = 0) -> NotificationsResult:
|
||||
"""загружаем уведомления"""
|
||||
user_id = info.context["user_id"]
|
||||
|
||||
with local_session() as session:
|
||||
author = session.query(Author).filter(Author.user == user_id).first()
|
||||
|
||||
nslist = (
|
||||
query = (
|
||||
session.query(Notification)
|
||||
.outerjoin(
|
||||
NotificationSeen,
|
||||
|
@ -70,15 +69,13 @@ class Query:
|
|||
)
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
.all()
|
||||
)
|
||||
|
||||
for notification in nslist:
|
||||
notification.seen_by_viewer = notification_seen_by_viewer(author.id, notification.id, session)
|
||||
|
||||
nslist = query.all()
|
||||
total = query.group_by(Notification.id).count()
|
||||
unread = sum(1 for n in nslist if not n.seen_by_viewer)
|
||||
|
||||
return NotificationsResult(notifications=nslist, unread=unread)
|
||||
return NotificationsResult(notifications=nslist, unread=unread, total=total)
|
||||
|
||||
|
||||
@strawberry.type
|
||||
|
|
Loading…
Reference in New Issue
Block a user