From 7b62b6be86bebb5175d623479740f3b70476fc4c Mon Sep 17 00:00:00 2001 From: Vito0912 <86927734+Vito0912@users.noreply.github.com> Date: Sat, 17 May 2025 18:02:23 +0200 Subject: [PATCH] task notifications --- server/SocketAuthority.js | 8 +++--- server/utils/notifications.js | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/server/SocketAuthority.js b/server/SocketAuthority.js index 6d13d42e..46ee66f6 100644 --- a/server/SocketAuthority.js +++ b/server/SocketAuthority.js @@ -17,7 +17,7 @@ class SocketAuthority { constructor() { this.Server = null this.socketIoServers = [] - this.emittedNotifications = new Set(['item_added', 'item_updated', 'user_online']); + this.emittedNotifications = new Set(['item_added', 'item_updated', 'user_online', 'task_started', 'task_finished']); /** @type {Object.} */ this.clients = {} @@ -69,7 +69,7 @@ class SocketAuthority { * @param {Function} [filter] optional filter function to only send event to specific users */ emitter(evt, data, filter = null) { - void this._fireNotification(evt, data) + void this._fireNotification(evt, flattenAny(data)) for (const socketId in this.clients) { if (this.clients[socketId].user) { if (filter && !filter(this.clients[socketId].user)) continue @@ -81,7 +81,7 @@ class SocketAuthority { // Emits event to all clients for a specific user clientEmitter(userId, evt, data) { - void this._fireNotification(evt, data) + void this._fireNotification(evt, flattenAny(data)) const clients = this.getClientsForUser(userId) if (!clients.length) { return Logger.debug(`[SocketAuthority] clientEmitter - no clients found for user ${userId}`) @@ -95,7 +95,7 @@ class SocketAuthority { // Emits event to all admin user clients adminEmitter(evt, data) { - void this._fireNotification(evt, data); + void this._fireNotification(evt, flattenAny(data)); for (const socketId in this.clients) { if (this.clients[socketId].user?.isAdminOrUp) { this.clients[socketId].socket.emit(evt, data) diff --git a/server/utils/notifications.js b/server/utils/notifications.js index dccd43b6..82976711 100644 --- a/server/utils/notifications.js +++ b/server/utils/notifications.js @@ -173,6 +173,57 @@ module.exports.notificationData = { body: 'User {{username}} (ID: {{id}}) is now online.' }, }, + { + name: 'onTaskStarted', + requiresLibrary: false, + description: 'Triggered when a task starts', + descriptionKey: 'NotificationOnTaskStartedDescription', + variables: [ + 'id', 'action', + 'data.libraryId', 'data.libraryName', + 'title', 'titleKey', + 'titleSubs', 'description', + 'descriptionKey', 'descriptionSubs', + 'error', 'errorKey', + 'errorSubs', 'showSuccess', + 'isFailed', 'isFinished', + 'startedAt', 'finishedAt' + ], + defaults: { + title: 'Task Started: {{title}}', + body: 'Task {{title}} has started.\n\nAction: {{action}}\nLibrary ID: {{data.libraryId}}\nLibrary Name: {{data.libraryName}}' + }, + }, + { + name: 'onTaskFinished', + requiresLibrary: false, + description: 'Triggered when a task finishes', + descriptionKey: 'NotificationOnTaskFinishesDescription', + variables: [ + 'id', + 'action', + 'data.libraryId', + 'data.libraryName', + 'title', + 'titleKey', + 'titleSubs', + 'description', + 'descriptionKey', + 'descriptionSubs', + 'error', + 'errorKey', + 'errorSubs', + 'showSuccess', + 'isFailed', + 'isFinished', + 'startedAt', + 'finishedAt' + ], + defaults: { + title: 'Task Started: {{title}}', + body: 'Task {{title}} has started.\n\nAction: {{action}}\nLibrary ID: {{data.libraryId}}\nLibrary Name: {{data.libraryName}}' + }, + }, // Test {