This commit is contained in:
Vito0912 2025-05-17 18:08:05 +02:00
parent 39f59e5189
commit dc41ccc377
No known key found for this signature in database
GPG Key ID: 29A3D509FE70B237
3 changed files with 11 additions and 45 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', 'task_started', 'task_finished']);
this.emittedNotifications = new Set(['item_added', 'item_updated', 'user_online', 'task_started', 'task_finished'])
/** @type {Object.<string, SocketClient>} */
this.clients = {}
@ -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, data)
for (const socketId in this.clients) {
if (this.clients[socketId].user?.isAdminOrUp) {
this.clients[socketId].socket.emit(evt, data)

View File

@ -189,11 +189,8 @@ class NotificationManager {
fireNotificationFromSocket(eventName, eventData) {
if (!Database.notificationSettings.isUseable) return
const eventNameModified = eventName.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
const eventKey = `on${eventNameModified.charAt(0).toUpperCase()}${eventNameModified.slice(1)}`;
console.log(eventData)
console.log(Object.keys(eventData))
const eventNameModified = eventName.replace(/_([a-z])/g, (_, c) => c.toUpperCase())
const eventKey = `on${eventNameModified.charAt(0).toUpperCase()}${eventNameModified.slice(1)}`
if (!Database.notificationSettings.getHasActiveNotificationsForEvent(eventKey)) {
// No logging to prevent console spam

View File

@ -72,9 +72,7 @@ const libraryItemTestData = {
updatedAt: new Date('2024-05-15T18:30:36.940Z'),
libraryId: 'fedcba98-7654-3210-fedc-ba9876543210',
libraryFolderId: '11223344-5566-7788-99aa-bbccddeeff00'
};
}
module.exports.notificationData = {
events: [
@ -167,62 +165,33 @@ module.exports.notificationData = {
requiresLibrary: false,
description: 'Triggered when a user comes online',
descriptionKey: 'NotificationOnUserOnlineDescription',
variables: [ 'id', 'username', 'type', 'session', 'lastSeen', 'createdAt'],
variables: ['id', 'username', 'type', 'session', 'lastSeen', 'createdAt'],
defaults: {
title: 'User Online: {{username}}',
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'
],
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'
],
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