feat: 已添加配方通知联动
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 16s
Test / e2e-test (push) Failing after 52s
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 16s
Test / e2e-test (push) Failing after 52s
- 点击"已添加"后:
1. 标记所有同标题通知为已读(其他编辑者不用重复处理)
2. 通知其他管理员/高级编辑"已有人添加,无需重复处理"
3. 通知原始搜索用户"你搜索的配方已添加"
- 新增 /api/notifications/{id}/added 端点
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1601,6 +1601,50 @@ def mark_notification_read(nid: int, body: dict = None, user=Depends(get_current
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@app.post("/api/notifications/{nid}/added")
|
||||
def mark_notification_added(nid: int, user=Depends(get_current_user)):
|
||||
"""Mark a 'search missing' notification as handled: notify others and the original requester."""
|
||||
conn = get_db()
|
||||
notif = conn.execute("SELECT title, body FROM notifications WHERE id = ?", (nid,)).fetchone()
|
||||
if not notif:
|
||||
conn.close()
|
||||
raise HTTPException(404, "通知不存在")
|
||||
# Mark this one as read
|
||||
conn.execute("UPDATE notifications SET is_read = 1 WHERE id = ?", (nid,))
|
||||
who = user.get("display_name") or user.get("username")
|
||||
title = notif["title"] or ""
|
||||
# Extract query from title "🔍 用户需求:XXX"
|
||||
query = title.replace("🔍 用户需求:", "").strip() if "用户需求" in title else title
|
||||
# Mark all same-title notifications as read
|
||||
conn.execute("UPDATE notifications SET is_read = 1 WHERE title = ? AND is_read = 0", (title,))
|
||||
# Notify other editors that it's been handled
|
||||
for role in ("admin", "senior_editor"):
|
||||
conn.execute(
|
||||
"INSERT INTO notifications (target_role, title, body) VALUES (?, ?, ?)",
|
||||
(role, "✅ 配方已添加",
|
||||
f"{who} 已为「{query}」添加了配方,无需重复处理。")
|
||||
)
|
||||
# Notify the original requester (search the body for who searched)
|
||||
body_text = notif["body"] or ""
|
||||
# body format: "XXX 搜索了「YYY」..."
|
||||
if "搜索了" in body_text:
|
||||
requester_name = body_text.split(" 搜索了")[0].strip()
|
||||
# Find the user
|
||||
requester = conn.execute(
|
||||
"SELECT id, role FROM users WHERE display_name = ? OR username = ?",
|
||||
(requester_name, requester_name)
|
||||
).fetchone()
|
||||
if requester:
|
||||
conn.execute(
|
||||
"INSERT INTO notifications (target_role, title, body, target_user_id) VALUES (?, ?, ?, ?)",
|
||||
(requester["role"], "🎉 你搜索的配方已添加",
|
||||
f"你之前搜索的「{query}」已有编辑添加了配方,快去查看吧!", requester["id"])
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@app.post("/api/notifications/{nid}/unread")
|
||||
def mark_notification_unread(nid: int, user=Depends(get_current_user)):
|
||||
conn = get_db()
|
||||
|
||||
@@ -141,7 +141,13 @@ function isReviewable(n) {
|
||||
}
|
||||
|
||||
async function markAdded(n) {
|
||||
await markOneRead(n)
|
||||
try {
|
||||
await api(`/api/notifications/${n.id}/added`, { method: 'POST' })
|
||||
n.is_read = 1
|
||||
ui.showToast('已标记,已通知相关人员')
|
||||
} catch {
|
||||
await markOneRead(n)
|
||||
}
|
||||
}
|
||||
|
||||
function goReview(n) {
|
||||
|
||||
Reference in New Issue
Block a user