task notifications

This commit is contained in:
Vito0912 2025-05-17 18:02:23 +02:00
parent 9e28ee036f
commit 7b62b6be86
No known key found for this signature in database
GPG Key ID: 29A3D509FE70B237
2 changed files with 55 additions and 4 deletions

View File

@ -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.<string, SocketClient>} */
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)

View File

@ -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
{