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:
@@ -18,6 +18,11 @@ ROWS = [ # 최신순(list_notifications 와 같게)
|
||||
|
||||
|
||||
class FakeStore:
|
||||
desktop = False
|
||||
|
||||
def notifier_active(self, email):
|
||||
return self.desktop
|
||||
|
||||
def list_notifications(self, recipient_email, unread_only=False, limit=100):
|
||||
rows = [r for r in ROWS if not unread_only or not r["is_read"]]
|
||||
return rows[:limit]
|
||||
@@ -29,9 +34,11 @@ class AlertsApiTests(unittest.TestCase):
|
||||
app.include_router(api.router)
|
||||
self.client = TestClient(app)
|
||||
|
||||
def get(self, qs=""):
|
||||
def get(self, qs="", desktop=False):
|
||||
st = FakeStore()
|
||||
st.desktop = desktop
|
||||
with patch.object(api, "_require_user", return_value={"email": "Me@Test.local"}), \
|
||||
patch.object(api, "_db_or_503", return_value=FakeStore()), \
|
||||
patch.object(api, "_db_or_503", return_value=st), \
|
||||
patch.object(api, "_visible_notifications", side_effect=lambda st, user, items: items):
|
||||
return self.client.get("/project/api/notifications/alerts" + qs).json()
|
||||
|
||||
@@ -43,6 +50,21 @@ class AlertsApiTests(unittest.TestCase):
|
||||
out = self.get("?after=5")
|
||||
self.assertEqual([a["id"] for a in out["alerts"]], [6, 8]) # 완료 알림(9)·읽은 것(7)·옛것(2) 제외
|
||||
self.assertEqual(out["alerts"][1]["type"], "mention")
|
||||
self.assertNotIn("desktop", out)
|
||||
|
||||
def test_pc_notifier_running_silences_web_popup(self):
|
||||
out = self.get("?after=5", desktop=True)
|
||||
self.assertEqual((out["alerts"], out["latest_id"], out["desktop"]), ([], 9, True))
|
||||
|
||||
def test_notifier_check_failure_keeps_web_popup(self):
|
||||
class Broken(FakeStore):
|
||||
def notifier_active(self, email):
|
||||
raise RuntimeError("db down")
|
||||
with patch.object(api, "_require_user", return_value={"email": "me@test.local"}), \
|
||||
patch.object(api, "_db_or_503", return_value=Broken()), \
|
||||
patch.object(api, "_visible_notifications", side_effect=lambda st, user, items: items):
|
||||
out = self.client.get("/project/api/notifications/alerts?after=5").json()
|
||||
self.assertEqual([a["id"] for a in out["alerts"]], [6, 8])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user