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