mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
45 lines
1.0 KiB
JavaScript
45 lines
1.0 KiB
JavaScript
|
class NotificationSettings {
|
||
|
constructor(settings = null) {
|
||
|
this.id = 'notification-settings'
|
||
|
this.appriseType = 'api'
|
||
|
this.appriseApiUrl = null
|
||
|
this.notifications = []
|
||
|
|
||
|
if (settings) {
|
||
|
this.construct(settings)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
construct(settings) {
|
||
|
this.appriseType = settings.appriseType
|
||
|
this.appriseApiUrl = settings.appriseApiUrl || null
|
||
|
this.notifications = (settings.notifications || []).map(n => ({ ...n }))
|
||
|
}
|
||
|
|
||
|
toJSON() {
|
||
|
return {
|
||
|
id: this.id,
|
||
|
appriseType: this.appriseType,
|
||
|
appriseApiUrl: this.appriseApiUrl,
|
||
|
notifications: this.notifications.map(n => n.toJSON())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
get isUseable() {
|
||
|
return !!this.appriseApiUrl
|
||
|
}
|
||
|
|
||
|
getNotificationsForEvent(eventName) {
|
||
|
return this.notifications.filter(n => n.eventName === eventName)
|
||
|
}
|
||
|
|
||
|
update(payload) {
|
||
|
if (!payload) return false
|
||
|
if (payload.appriseApiUrl !== this.appriseApiUrl) {
|
||
|
this.appriseApiUrl = payload.appriseApiUrl || null
|
||
|
return true
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
module.exports = NotificationSettings
|