@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user