fix(gateway): scope notification wakeups to session

This commit is contained in:
Ayaan Zaidi
2026-02-28 10:33:12 +05:30
committed by Ayaan Zaidi
parent 9d3ccf4754
commit f1bb26642c
3 changed files with 32 additions and 3 deletions

View File

@@ -137,6 +137,9 @@ class DeviceNotificationListenerService : NotificationListenerService() {
super.onNotificationPosted(sbn)
val entry = sbn?.toEntry() ?: return
DeviceNotificationStore.upsert(entry)
if (entry.packageName == packageName) {
return
}
emitNotificationsChanged(
buildJsonObject {
put("change", JsonPrimitive("posted"))
@@ -162,6 +165,9 @@ class DeviceNotificationListenerService : NotificationListenerService() {
return
}
DeviceNotificationStore.remove(key)
if (removed.packageName == packageName) {
return
}
emitNotificationsChanged(
buildJsonObject {
put("change", JsonPrimitive("removed"))

View File

@@ -374,7 +374,10 @@ describe("notifications changed events", () => {
"Notification posted (node=node-n1 key=notif-1 package=com.example.chat): Message - Ping from Alex",
{ sessionKey: "node-node-n1", contextKey: "notification:notif-1" },
);
expect(requestHeartbeatNowMock).toHaveBeenCalledWith({ reason: "notifications-event" });
expect(requestHeartbeatNowMock).toHaveBeenCalledWith({
reason: "notifications-event",
sessionKey: "node-node-n1",
});
});
it("enqueues notifications.changed removed events", async () => {
@@ -392,7 +395,27 @@ describe("notifications changed events", () => {
"Notification removed (node=node-n2 key=notif-2 package=com.example.mail)",
{ sessionKey: "node-node-n2", contextKey: "notification:notif-2" },
);
expect(requestHeartbeatNowMock).toHaveBeenCalledWith({ reason: "notifications-event" });
expect(requestHeartbeatNowMock).toHaveBeenCalledWith({
reason: "notifications-event",
sessionKey: "node-node-n2",
});
});
it("wakes heartbeat on payload sessionKey when provided", async () => {
const ctx = buildCtx();
await handleNodeEvent(ctx, "node-n4", {
event: "notifications.changed",
payloadJSON: JSON.stringify({
change: "posted",
key: "notif-4",
sessionKey: "agent:main:main",
}),
});
expect(requestHeartbeatNowMock).toHaveBeenCalledWith({
reason: "notifications-event",
sessionKey: "agent:main:main",
});
});
it("ignores notifications.changed payloads missing required fields", async () => {

View File

@@ -485,7 +485,7 @@ export const handleNodeEvent = async (ctx: NodeEventContext, nodeId: string, evt
}
enqueueSystemEvent(summary, { sessionKey, contextKey: `notification:${key}` });
requestHeartbeatNow({ reason: "notifications-event" });
requestHeartbeatNow({ reason: "notifications-event", sessionKey });
return;
}
case "chat.subscribe": {