feat(project): silence web alert popup while PC notifier is running
If the user has a non-revoked notifier token seen in the last 3 minutes, /api/notifications/alerts returns only the baseline with desktop=true; the web marks it seen so alerts resume on the web after the app stops. A failing check keeps the web popup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1657,6 +1657,20 @@ class ProjectStore:
|
||||
).fetchone()
|
||||
return row["email"] if row else None
|
||||
|
||||
def notifier_active(self, *, email: str, within_sec: int = 180) -> bool:
|
||||
"""이 사용자의 PC 알림 프로그램이 지금 돌고 있나 — 해제 안 된 토큰 중 최근(기본 3분) 확인한 것이 있으면 True.
|
||||
프로그램은 20초마다 확인하고 last_seen_at 은 1분에 한 번 갱신되므로 3분이면 꺼진 PC 는 곧 빠진다. 023 미적용이면 False."""
|
||||
try:
|
||||
with self._pool.connection() as conn:
|
||||
row = conn.execute(
|
||||
"SELECT 1 FROM notifier_tokens WHERE email = %s AND revoked_at IS NULL "
|
||||
"AND last_seen_at > now() - make_interval(secs => %s) LIMIT 1",
|
||||
(store.norm_str(email, lower=True), within_sec),
|
||||
).fetchone()
|
||||
except psycopg_errors.UndefinedTable:
|
||||
return False
|
||||
return row is not None
|
||||
|
||||
def notifier_revoke_token(self, *, token: str) -> None:
|
||||
with self._pool.connection() as conn:
|
||||
conn.execute("UPDATE notifier_tokens SET revoked_at = now() WHERE token_hash = %s AND revoked_at IS NULL",
|
||||
|
||||
@@ -2299,9 +2299,22 @@ def api_notification_alerts(request: Request, after: int = -1) -> JSONResponse:
|
||||
처음 쓰는 브라우저가 쌓인 옛 알림을 한꺼번에 띄우지 않게."""
|
||||
user = _require_user(request)
|
||||
st = _db_or_503(request)
|
||||
# PC 알림 프로그램이 돌고 있으면(023, 최근 3분 안에 확인) 웹 팝업은 띄우지 않는다 — 기준점(latest_id)만 주고
|
||||
# desktop=True. 웹은 그 번호까지 본 것으로 두어, 프로그램을 끄면 그 뒤에 온 알림부터 다시 웹에 뜬다.
|
||||
if _notifier_active(st, user):
|
||||
out = _alerts_payload(st, user, -1)
|
||||
out["desktop"] = True
|
||||
return JSONResponse(out)
|
||||
return JSONResponse(_alerts_payload(st, user, after))
|
||||
|
||||
|
||||
def _notifier_active(st: Any, user: dict[str, Any]) -> bool:
|
||||
try:
|
||||
return bool(st.notifier_active(email=user["email"]))
|
||||
except Exception: # noqa: BLE001 — 확인 실패면 웹 팝업을 그대로(알림을 놓치지 않게)
|
||||
return False
|
||||
|
||||
|
||||
def _alerts_payload(st: Any, user: dict[str, Any], after: int) -> dict[str, Any]:
|
||||
"""큰 팝업 알림 — 웹 화면(initTaskAlerts)과 PC 알림 프로그램이 같이 쓴다."""
|
||||
newest = st.list_notifications(recipient_email=user["email"], limit=1)
|
||||
|
||||
Reference in New Issue
Block a user