seen-fix
All checks were successful
deploy / deploy (push) Successful in 1m20s

This commit is contained in:
2023-12-22 16:42:37 +03:00
parent 051d35869b
commit 674bc9ce63
4 changed files with 53 additions and 13 deletions

View File

@@ -8,7 +8,7 @@ from resolvers.model import (
NotificationsResult,
)
from orm.notification import NotificationSeen
from typing import Dict
from typing import Dict, List
import time, json
import strawberry
from sqlalchemy.orm import aliased
@@ -17,7 +17,7 @@ from sqlalchemy import select, and_
async def get_notifications_grouped(
author_id: int, after: int = 0, limit: int = 10, offset: int = 0, mark_as_read=False
) -> Dict[str, NotificationGroup]:
):
"""
Retrieves notifications for a given author.
@@ -53,8 +53,13 @@ async def get_notifications_grouped(
notifications: Dict[str, NotificationGroup] = {}
counter = 0
unread = 0
total = 0
with local_session() as session:
for n, seen in session.execute(query):
notifications_result = session.execute(query)
for n, seen in notifications_result:
total += 1
unread += 1 if author_id in n.seen else 0
thread_id = ""
payload = json.loads(n.payload)
print(f"[resolvers.schema] {n.action} {n.entity}: {payload}")
@@ -142,7 +147,7 @@ async def get_notifications_grouped(
if counter > limit:
break
return notifications
return notifications, unread, total
@strawberry.type
@@ -152,8 +157,6 @@ class Query:
author_id = info.context.get("author_id")
notification_groups: Dict[str, NotificationGroup] = {}
if author_id:
# TODO: add total counter calculation
# TODO: add unread counter calculation
notification_groups = await get_notifications_grouped(author_id, after, limit, offset)
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)
return NotificationsResult(notifications=notifications, total=0, unread=0, error=None)