diff --git a/db/patch9.sql b/db/patch9.sql new file mode 100644 index 000000000..3f631ff8b --- /dev/null +++ b/db/patch9.sql @@ -0,0 +1,7 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; + +ALTER TABLE notification + ADD is_default BOOLEAN; + +COMMIT; diff --git a/server/database.js b/server/database.js index 77c4da758..832166d2c 100644 --- a/server/database.js +++ b/server/database.js @@ -7,7 +7,7 @@ class Database { static templatePath = "./db/kuma.db" static dataDir; static path; - static latestVersion = 8; + static latestVersion = 9; static noReject = true; static sqliteInstance = null; diff --git a/server/notification.js b/server/notification.js index 472012af7..d3a55c841 100644 --- a/server/notification.js +++ b/server/notification.js @@ -617,8 +617,13 @@ class Notification { bean.name = notification.name; bean.user_id = userID; - bean.config = JSON.stringify(notification) + bean.config = JSON.stringify(notification); + bean.is_default = notification.isDefault; await R.store(bean) + + if (notification.applyExisting) { + await applyNotificationEveryMonitor(bean.id, userID); + } } static async delete(notificationID, userID) { @@ -702,6 +707,26 @@ function throwGeneralAxiosError(error) { throw new Error(msg) } +async function applyNotificationEveryMonitor(notificationID, userID) { + let monitors = await R.getAll("SELECT id FROM monitor WHERE user_id = ?", [ + userID + ]); + + for (let i = 0; i < monitors.length; i++) { + let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [ + monitors[i].id, + notificationID, + ]) + + if (! checkNotification) { + let relation = R.dispense("monitor_notification"); + relation.monitor_id = monitors[i].id; + relation.notification_id = notificationID; + await R.store(relation) + } + } +} + module.exports = { Notification, } diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 2fdb8fe18..fa63a376c 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -469,6 +469,25 @@ First access the Line Developers Console, create a provider and channel (Messaging API), then you can get the channel access token and user id from the above mentioned menu items. + +