This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import time
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
import orjson
|
||||
@@ -32,16 +33,21 @@ def query_notifications(author_id: int, after: int = 0) -> tuple[int, int, list[
|
||||
),
|
||||
)
|
||||
if after:
|
||||
q = q.where(Notification.created_at > after)
|
||||
# Convert Unix timestamp to datetime for PostgreSQL compatibility
|
||||
after_datetime = datetime.fromtimestamp(after)
|
||||
q = q.where(Notification.created_at > after_datetime)
|
||||
q = q.group_by(NotificationSeen.notification, Notification.created_at)
|
||||
|
||||
with local_session() as session:
|
||||
# Convert Unix timestamp to datetime for PostgreSQL compatibility
|
||||
after_datetime = datetime.fromtimestamp(after) if after else None
|
||||
|
||||
total = (
|
||||
session.query(Notification)
|
||||
.where(
|
||||
and_(
|
||||
Notification.action == NotificationAction.CREATE.value,
|
||||
Notification.created_at > after,
|
||||
Notification.created_at > after_datetime,
|
||||
)
|
||||
)
|
||||
.count()
|
||||
@@ -52,7 +58,7 @@ def query_notifications(author_id: int, after: int = 0) -> tuple[int, int, list[
|
||||
.where(
|
||||
and_(
|
||||
Notification.action == NotificationAction.CREATE.value,
|
||||
Notification.created_at > after,
|
||||
Notification.created_at > after_datetime,
|
||||
not_(Notification.seen),
|
||||
)
|
||||
)
|
||||
@@ -260,7 +266,9 @@ async def notifications_seen_after(_: None, info: GraphQLResolveInfo, after: int
|
||||
author_id = info.context.get("author", {}).get("id")
|
||||
if author_id:
|
||||
with local_session() as session:
|
||||
nnn = session.query(Notification).where(and_(Notification.created_at > after)).all()
|
||||
# Convert Unix timestamp to datetime for PostgreSQL compatibility
|
||||
after_datetime = datetime.fromtimestamp(after) if after else None
|
||||
nnn = session.query(Notification).where(and_(Notification.created_at > after_datetime)).all()
|
||||
for notification in nnn:
|
||||
ns = NotificationSeen(notification=notification.id, author=author_id)
|
||||
session.add(ns)
|
||||
@@ -279,13 +287,16 @@ async def notifications_seen_thread(_: None, info: GraphQLResolveInfo, thread: s
|
||||
if author_id:
|
||||
[shout_id, reply_to_id] = thread.split(":")
|
||||
with local_session() as session:
|
||||
# Convert Unix timestamp to datetime for PostgreSQL compatibility
|
||||
after_datetime = datetime.fromtimestamp(after) if after else None
|
||||
|
||||
# TODO: handle new follower and new shout notifications
|
||||
new_reaction_notifications = (
|
||||
session.query(Notification)
|
||||
.where(
|
||||
Notification.action == "create",
|
||||
Notification.entity == "reaction",
|
||||
Notification.created_at > after,
|
||||
Notification.created_at > after_datetime,
|
||||
)
|
||||
.all()
|
||||
)
|
||||
@@ -294,7 +305,7 @@ async def notifications_seen_thread(_: None, info: GraphQLResolveInfo, thread: s
|
||||
.where(
|
||||
Notification.action == "delete",
|
||||
Notification.entity == "reaction",
|
||||
Notification.created_at > after,
|
||||
Notification.created_at > after_datetime,
|
||||
)
|
||||
.all()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user