after-fix
All checks were successful
deploy / deploy (push) Successful in 1m7s

This commit is contained in:
Untone 2023-12-18 18:41:46 +03:00
parent 25b6a6f50a
commit 5c6a680832

View File

@ -1,5 +1,6 @@
import logging import logging
from typing import List from typing import List
from sqlalchemy.schema import Column
import strawberry import strawberry
from sqlalchemy import and_, select from sqlalchemy import and_, select
@ -42,7 +43,7 @@ class NotificationsResult:
total: int total: int
def get_notifications(author_id: int, session, after: int, limit: int = 9999, offset: int = 0) -> List[Notification]: def get_notifications(author_id: int, session, after: int | Column[int], limit: int = 9999, offset: int = 0) -> List[Notification]:
NotificationSeenAlias = aliased(NotificationSeen) NotificationSeenAlias = aliased(NotificationSeen)
query = ( query = (
select(NotificationMessage, NotificationSeenAlias.viewer.label("seen")) select(NotificationMessage, NotificationSeenAlias.viewer.label("seen"))
@ -76,13 +77,11 @@ def get_notifications(author_id: int, session, after: int, limit: int = 9999, of
@strawberry.type @strawberry.type
class Query: class Query:
@strawberry.field @strawberry.field
async def load_notifications(self, info, limit: int = 50, offset: int = 0) -> NotificationsResult: async def load_notifications(self, info, after: int, limit: int = 50, offset: int = 0) -> NotificationsResult:
author_id = info.context.get("author_id") author_id = info.context.get("author_id")
with local_session() as session: with local_session() as session:
try: try:
if author_id: if author_id:
author = session.query(Author).filter(Author.id == author_id).first()
after = author.last_seen
notifications = get_notifications(author_id, session, after, limit, offset) notifications = get_notifications(author_id, session, after, limit, offset)
if notifications and len(notifications) > 0: if notifications and len(notifications) > 0:
nr = NotificationsResult( nr = NotificationsResult(
@ -124,7 +123,10 @@ class Mutation:
if author_id: if author_id:
with local_session() as session: with local_session() as session:
try: try:
nslist = get_notifications(author_id, session) author = session.query(Author).filter(Author.id == author_id).first()
if author:
after = author.last_seen
nslist = get_notifications(author_id, session, after)
for n in nslist: for n in nslist:
if author_id not in n.seen: if author_id not in n.seen:
ns = NotificationSeen(viewer=author_id, notification=n.id) ns = NotificationSeen(viewer=author_id, notification=n.id)