fix notice display
This commit is contained in:
+19
-7
@@ -966,16 +966,28 @@ function createApp({
|
|||||||
const notificationId = String(event.notificationId || "");
|
const notificationId = String(event.notificationId || "");
|
||||||
if (!notificationId) return { success: false, errMsg: "缺少 notificationId" };
|
if (!notificationId) return { success: false, errMsg: "缺少 notificationId" };
|
||||||
return store.update((database) => {
|
return store.update((database) => {
|
||||||
const exists = database.panelNotifications.some((item) =>
|
const exactMatch = database.panelNotifications.find((item) =>
|
||||||
item.deviceId === deviceId && item.notificationId === notificationId
|
item.deviceId === deviceId && item.notificationId === notificationId
|
||||||
);
|
);
|
||||||
if (!exists) {
|
if (exactMatch) {
|
||||||
return { success: false, errMsg: "Panel 通知不存在" };
|
database.panelNotifications = database.panelNotifications.filter((item) => item !== exactMatch);
|
||||||
|
return { success: true, notificationId, deleted: 1 };
|
||||||
}
|
}
|
||||||
database.panelNotifications = database.panelNotifications.filter((item) =>
|
|
||||||
!(item.deviceId === deviceId && item.notificationId === notificationId)
|
// 兼容:客户端 deviceId 切换或重连后,允许仅凭 notificationId 完成幂等关闭。
|
||||||
);
|
const fallbackMatch = database.panelNotifications.find((item) => item.notificationId === notificationId);
|
||||||
return { success: true, notificationId, deleted: 1 };
|
if (fallbackMatch) {
|
||||||
|
database.panelNotifications = database.panelNotifications.filter((item) => item !== fallbackMatch);
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
notificationId,
|
||||||
|
deleted: 1,
|
||||||
|
idempotent: true,
|
||||||
|
reassignedDeviceId: fallbackMatch.deviceId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: true, notificationId, deleted: 0, idempotent: true };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case "ackPanelFile": {
|
case "ackPanelFile": {
|
||||||
|
|||||||
@@ -552,8 +552,12 @@ test("panel notifications and volume configuration stay isolated by device", asy
|
|||||||
type: "ackPanelNotification", deviceId, notificationId: notification.notification.notificationId,
|
type: "ackPanelNotification", deviceId, notificationId: notification.notification.notificationId,
|
||||||
adminToken: "test-token"
|
adminToken: "test-token"
|
||||||
});
|
});
|
||||||
assert.equal(duplicatedAck.success, false);
|
assert.equal(duplicatedAck.success, true);
|
||||||
assert.equal(duplicatedAck.errMsg, "Panel 通知不存在");
|
assert.equal(duplicatedAck.idempotent, true);
|
||||||
|
assert.equal(duplicatedAck.deleted, 0);
|
||||||
|
assert.equal((await post({
|
||||||
|
type: "getPendingPanelNotification", deviceId, adminToken: "test-token"
|
||||||
|
})).pending, false);
|
||||||
|
|
||||||
async function uploadResult(folderName, fileName, content) {
|
async function uploadResult(folderName, fileName, content) {
|
||||||
const result = await post({ type: "uploadDataFile", fileName, folder: `${deviceId}/${folderName}` });
|
const result = await post({ type: "uploadDataFile", fileName, folder: `${deviceId}/${folderName}` });
|
||||||
@@ -567,6 +571,15 @@ test("panel notifications and volume configuration stay isolated by device", asy
|
|||||||
});
|
});
|
||||||
assert.equal(volumeResult.notification.type, "volume_result_ready");
|
assert.equal(volumeResult.notification.type, "volume_result_ready");
|
||||||
assert.ok(volumeResult.notification.fileID);
|
assert.ok(volumeResult.notification.fileID);
|
||||||
|
const fallbackAck = await post({
|
||||||
|
type: "ackPanelNotification",
|
||||||
|
deviceId: otherDeviceId,
|
||||||
|
notificationId: volumeResult.notification.notificationId,
|
||||||
|
adminToken: "test-token"
|
||||||
|
});
|
||||||
|
assert.equal(fallbackAck.success, true);
|
||||||
|
assert.equal(fallbackAck.idempotent, true);
|
||||||
|
assert.equal(fallbackAck.deleted, 1);
|
||||||
await post({
|
await post({
|
||||||
type: "ackPanelNotification", deviceId, notificationId: volumeResult.notification.notificationId,
|
type: "ackPanelNotification", deviceId, notificationId: volumeResult.notification.notificationId,
|
||||||
adminToken: "test-token"
|
adminToken: "test-token"
|
||||||
|
|||||||
Reference in New Issue
Block a user