diff --git a/resolvers/load.py b/resolvers/load.py index 7108a33..6a71917 100644 --- a/resolvers/load.py +++ b/resolvers/load.py @@ -35,8 +35,9 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int = { entity: str, # Type of entity (e.g., 'reaction', 'shout', 'follower'). updated_at: int, # Timestamp of the latest update in the thread. - reactions: List[Reaction], # List of reactions within the thread. - authors: List[Author], # List of authors involved in the thread. + shout: Optional[NotificationShout] + reactions: List[int], # List of reaction ids within the thread. + authors: List[NotificationAuthor], # List of authors involved in the thread. } """ NotificationSeenAlias = aliased(NotificationSeen) @@ -93,7 +94,7 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int = if reaction.reply_to: thread_id += f"{'::' + str(reaction.reply_to)}" group: NotificationGroup | None = groups_by_thread.get(thread_id) - notifications: List[Notification] = notifications_by_thread.get(thread_id) + notifications: List[Notification] = notifications_by_thread.get(thread_id, []) if group and notifications: group.seen = False # any not seen notification make it false group.shout = shout @@ -161,7 +162,7 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int = if groups_amount > limit: break - return groups_by_thread, unread, total + return groups_by_thread, notifications_by_thread, unread, total @strawberry.type @@ -169,8 +170,8 @@ class Query: @strawberry.field async def load_notifications(self, info, after: int, limit: int = 50, offset: int = 0) -> NotificationsResult: author_id = info.context.get("author_id") - notification_groups: Dict[str, NotificationGroup] = {} + groups: Dict[str, NotificationGroup] = {} if author_id: - notification_groups, total, unread = await get_notifications_grouped(author_id, after, limit, offset) - notifications = sorted(notification_groups.values(), key=lambda group: group.updated_at, reverse=True) + groups, notifications, total, unread = await get_notifications_grouped(author_id, after, limit, offset) + notifications = sorted(groups.values(), key=lambda group: group.updated_at, reverse=True) return NotificationsResult(notifications=notifications, total=0, unread=0, error=None) diff --git a/resolvers/seen.py b/resolvers/seen.py index 4457245..b61a901 100644 --- a/resolvers/seen.py +++ b/resolvers/seen.py @@ -2,7 +2,6 @@ from sqlalchemy import and_ from orm.notification import NotificationSeen from services.db import local_session from resolvers.model import Notification, NotificationSeenResult, NotificationReaction -from resolvers.load import get_notifications_grouped from typing import List import strawberry import logging