feat(notify): 站内通知补齐完成、到期逾期与知识事件
CI / backend (push) Waiting to run

This commit is contained in:
Steven
2026-11-10 13:47:56 +08:00
parent 4b7627d70e
commit f54df70811
15 changed files with 791 additions and 32 deletions
+16 -4
View File
@@ -767,11 +767,14 @@ async def delete_link(
# -- 通知 ---------------------------------------------------------------
def _notification_out(n: Notification, item_title: str | None = None) -> dict[str, Any]:
def _notification_out(
n: Notification, item_title: str | None = None, item_kind: str | None = None
) -> dict[str, Any]:
return {
"id": str(n.id),
"kind": n.kind,
"item_id": str(n.item_id) if n.item_id else None,
"item_kind": item_kind,
"item_title": item_title,
"title": n.title,
"body": n.body,
@@ -813,18 +816,27 @@ async def list_notifications(
rows = list(rows[:limit])
titles: dict[uuid.UUID, str] = {}
kinds: dict[uuid.UUID, str] = {}
item_ids = [n.item_id for n in rows if n.item_id]
if item_ids:
for item_id, title in (
await session.execute(select(Item.id, Item.title).where(Item.id.in_(item_ids)))
for item_id, title, kind in (
await session.execute(
select(Item.id, Item.title, Item.kind).where(Item.id.in_(item_ids))
)
).all():
titles[item_id] = title
kinds[item_id] = kind
next_cursor = encode_cursor(rows[-1].created_at, rows[-1].id) if has_more and rows else None
return ok(
{
"notifications": [
_notification_out(n, titles.get(n.item_id) if n.item_id else None) for n in rows
_notification_out(
n,
titles.get(n.item_id) if n.item_id else None,
kinds.get(n.item_id) if n.item_id else None,
)
for n in rows
],
"next_cursor": next_cursor,
"has_more": has_more,