Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: showing the notification activation switch properly #5196

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ class Monitor extends BeanModel {
FROM monitor_notification
WHERE monitor_notification.monitor_id IN (?)
`, [
monitorIDs,
monitorIDs.join(","),
julian-piehl marked this conversation as resolved.
Show resolved Hide resolved
]);
}

Expand All @@ -1526,7 +1526,7 @@ class Monitor extends BeanModel {
JOIN tag ON monitor_tag.tag_id = tag.id
WHERE monitor_tag.monitor_id IN (?)
`, [
monitorIDs,
monitorIDs.join(","),
]);
}

Expand Down
12 changes: 8 additions & 4 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ let needSetup = false;

await updateMonitorNotification(bean.id, notificationIDList);

await server.sendUpdateMonitorIntoList(socket, bean.id);
await server.sendUpdateMonitorsIntoList(socket, bean.id);

if (monitor.active !== false) {
await startMonitor(socket.userID, bean.id);
Expand Down Expand Up @@ -884,7 +884,7 @@ let needSetup = false;
await restartMonitor(socket.userID, bean.id);
}

await server.sendUpdateMonitorIntoList(socket, bean.id);
await server.sendUpdateMonitorsIntoList(socket, bean.id);

callback({
ok: true,
Expand Down Expand Up @@ -985,7 +985,9 @@ let needSetup = false;
try {
checkLogin(socket);
await startMonitor(socket.userID, monitorID);
await server.sendUpdateMonitorIntoList(socket, monitorID);

const childrenIDs = await Monitor.getAllChildrenIDs(monitorID);
await server.sendUpdateMonitorsIntoList(socket, [ monitorID, ...childrenIDs ]);

callback({
ok: true,
Expand All @@ -1005,7 +1007,9 @@ let needSetup = false;
try {
checkLogin(socket);
await pauseMonitor(socket.userID, monitorID);
await server.sendUpdateMonitorIntoList(socket, monitorID);

const childrenIDs = await Monitor.getAllChildrenIDs(monitorID);
await server.sendUpdateMonitorsIntoList(socket, [ monitorID, ...childrenIDs ]);

callback({
ok: true,
Expand Down
24 changes: 13 additions & 11 deletions server/uptime-kuma-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,16 @@ class UptimeKumaServer {
/**
* Update Monitor into list
* @param {Socket} socket Socket to send list on
* @param {number} monitorID update or deleted monitor id
* @param {number | number[]} monitorIDs update or deleted monitor ids
* @returns {Promise<void>}
*/
async sendUpdateMonitorIntoList(socket, monitorID) {
let list = await this.getMonitorJSONList(socket.userID, monitorID);
this.io.to(socket.userID).emit("updateMonitorIntoList", list);
async sendUpdateMonitorsIntoList(socket, monitorIDs) {
if (!Array.isArray(monitorIDs)) {
monitorIDs = [ monitorIDs ];
}

let list = await this.getMonitorJSONList(socket.userID, monitorIDs);
this.io.to(socket.userID).emit("updateMonitorsIntoList", list);
}

/**
Expand All @@ -229,22 +233,20 @@ class UptimeKumaServer {
/**
* Get a list of monitors for the given user.
* @param {string} userID - The ID of the user to get monitors for.
* @param {number} monitorID - The ID of monitor for.
* @param {number[]} monitorIDs - The IDs of monitors for.
* @returns {Promise<object>} A promise that resolves to an object with monitor IDs as keys and monitor objects as values.
*
* Generated by Trelent
*/
async getMonitorJSONList(userID, monitorID = null) {
async getMonitorJSONList(userID, monitorIDs = null) {

let query = " user_id = ? ";
let queryParams = [ userID ];

if (monitorID) {
query += "AND id = ? ";
queryParams.push(monitorID);
if (monitorIDs) {
query += `AND id IN (${monitorIDs.join(",")}) `;
julian-piehl marked this conversation as resolved.
Show resolved Hide resolved
}

let monitorList = await R.find("monitor", query + "ORDER BY weight DESC, name", queryParams);
let monitorList = await R.find("monitor", query + "ORDER BY weight DESC, name", [ userID ]);

const monitorData = monitorList.map(monitor => ({
id: monitor.id,
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default {
this.monitorList = data;
});

socket.on("updateMonitorIntoList", (data) => {
socket.on("updateMonitorsIntoList", (data) => {
this.assignMonitorUrlParser(data);
Object.entries(data).forEach(([ monitorID, updatedMonitor ]) => {
this.monitorList[monitorID] = updatedMonitor;
Expand Down
Loading