mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-28 01:16:10 +02:00
task notifications
This commit is contained in:
parent
9e28ee036f
commit
7b62b6be86
@ -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)
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user