This commit is contained in:
parent
dbe4dd760b
commit
940fb121e4
|
@ -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').
|
entity: str, # Type of entity (e.g., 'reaction', 'shout', 'follower').
|
||||||
updated_at: int, # Timestamp of the latest update in the thread.
|
updated_at: int, # Timestamp of the latest update in the thread.
|
||||||
reactions: List[Reaction], # List of reactions within the thread.
|
shout: Optional[NotificationShout]
|
||||||
authors: List[Author], # List of authors involved in the thread.
|
reactions: List[int], # List of reaction ids within the thread.
|
||||||
|
authors: List[NotificationAuthor], # List of authors involved in the thread.
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
NotificationSeenAlias = aliased(NotificationSeen)
|
NotificationSeenAlias = aliased(NotificationSeen)
|
||||||
|
@ -93,7 +94,7 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int =
|
||||||
if reaction.reply_to:
|
if reaction.reply_to:
|
||||||
thread_id += f"{'::' + str(reaction.reply_to)}"
|
thread_id += f"{'::' + str(reaction.reply_to)}"
|
||||||
group: NotificationGroup | None = groups_by_thread.get(thread_id)
|
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:
|
if group and notifications:
|
||||||
group.seen = False # any not seen notification make it false
|
group.seen = False # any not seen notification make it false
|
||||||
group.shout = shout
|
group.shout = shout
|
||||||
|
@ -161,7 +162,7 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int =
|
||||||
if groups_amount > limit:
|
if groups_amount > limit:
|
||||||
break
|
break
|
||||||
|
|
||||||
return groups_by_thread, unread, total
|
return groups_by_thread, notifications_by_thread, unread, total
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
|
@ -169,8 +170,8 @@ class Query:
|
||||||
@strawberry.field
|
@strawberry.field
|
||||||
async def load_notifications(self, info, after: int, 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")
|
||||||
notification_groups: Dict[str, NotificationGroup] = {}
|
groups: Dict[str, NotificationGroup] = {}
|
||||||
if author_id:
|
if author_id:
|
||||||
notification_groups, total, unread = await get_notifications_grouped(author_id, after, limit, offset)
|
groups, notifications, total, unread = await get_notifications_grouped(author_id, after, limit, offset)
|
||||||
notifications = sorted(notification_groups.values(), key=lambda group: group.updated_at, reverse=True)
|
notifications = sorted(groups.values(), key=lambda group: group.updated_at, reverse=True)
|
||||||
return NotificationsResult(notifications=notifications, total=0, unread=0, error=None)
|
return NotificationsResult(notifications=notifications, total=0, unread=0, error=None)
|
||||||
|
|
|
@ -2,7 +2,6 @@ from sqlalchemy import and_
|
||||||
from orm.notification import NotificationSeen
|
from orm.notification import NotificationSeen
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
from resolvers.model import Notification, NotificationSeenResult, NotificationReaction
|
from resolvers.model import Notification, NotificationSeenResult, NotificationReaction
|
||||||
from resolvers.load import get_notifications_grouped
|
|
||||||
from typing import List
|
from typing import List
|
||||||
import strawberry
|
import strawberry
|
||||||
import logging
|
import logging
|
||||||
|
|
Loading…
Reference in New Issue
Block a user