New notification settings
This commit is contained in:
parent
90021ef2f6
commit
e0e8ed7996
@ -3,6 +3,19 @@ component InputText(id string, value string, label string, placeholder string)
|
|||||||
label(for=id)= label + ":"
|
label(for=id)= label + ":"
|
||||||
input.widget-ui-element.action(id=id, data-field=id, type="text", value=value, placeholder=placeholder, title=placeholder, data-action="save", data-trigger="change")
|
input.widget-ui-element.action(id=id, data-field=id, type="text", value=value, placeholder=placeholder, title=placeholder, data-action="save", data-trigger="change")
|
||||||
|
|
||||||
|
component InputBool(id string, value bool, label string, title string)
|
||||||
|
.widget-section
|
||||||
|
label(for=id)= label + ":"
|
||||||
|
if value
|
||||||
|
button.action(id=id, data-action="disable", data-trigger="click", data-field=id, title=title)
|
||||||
|
Icon("toggle-on")
|
||||||
|
span ON
|
||||||
|
else
|
||||||
|
button.action(id=id, data-action="enable", data-trigger="click", data-field=id, title=title)
|
||||||
|
Icon("toggle-off")
|
||||||
|
span OFF
|
||||||
|
//- input.widget-ui-element.action(id=id, data-field=id, type="checkbox", value=value, checked=value, data-action="save", data-trigger="change")
|
||||||
|
|
||||||
component InputTextArea(id string, value string, label string, placeholder string)
|
component InputTextArea(id string, value string, label string, placeholder string)
|
||||||
.widget-section
|
.widget-section
|
||||||
label(for=id)= label + ":"
|
label(for=id)= label + ":"
|
||||||
|
@ -89,25 +89,47 @@ component SettingsNotifications(user *arn.User)
|
|||||||
.widget.mountable
|
.widget.mountable
|
||||||
h3.widget-title
|
h3.widget-title
|
||||||
Icon("bell")
|
Icon("bell")
|
||||||
span Notifications
|
span Push notifications
|
||||||
|
|
||||||
#enable-notifications.widget-section
|
#enable-notifications.widget-section
|
||||||
label Enable:
|
label Enable:
|
||||||
button.action(data-action="enableNotifications", data-trigger="click")
|
button.action(data-action="enableNotifications", data-trigger="click")
|
||||||
Icon("toggle-off")
|
Icon("toggle-off")
|
||||||
span Enable notifications
|
span Enable push notifications
|
||||||
|
|
||||||
#disable-notifications.widget-section
|
#disable-notifications.widget-section.hidden
|
||||||
label Disable:
|
label Disable:
|
||||||
button.action(data-action="disableNotifications", data-trigger="click")
|
button.action(data-action="disableNotifications", data-trigger="click")
|
||||||
Icon("toggle-on")
|
Icon("toggle-on")
|
||||||
span Disable notifications
|
span Disable push notifications
|
||||||
|
|
||||||
#test-notification.widget-section
|
#test-notification.widget-section
|
||||||
label Test:
|
label Test:
|
||||||
button.action(data-action="testNotification", data-trigger="click")
|
button.action(data-action="testNotification", data-trigger="click")
|
||||||
Icon("paper-plane")
|
Icon("paper-plane")
|
||||||
span Send test notification
|
span Send test notification
|
||||||
|
|
||||||
|
.footer
|
||||||
|
p(title="This setting is not account bound, instead it is bound to your browser.") You can customize this setting on every device you own.
|
||||||
|
|
||||||
|
.widget.mountable(data-api="/api/settings/" + user.ID)
|
||||||
|
h3.widget-title
|
||||||
|
Icon("filter")
|
||||||
|
span General
|
||||||
|
|
||||||
|
InputBool("Notification.AnimeEpisodeReleases", user.Settings().Notification.AnimeEpisodeReleases, "New episodes", "Notifications about new episodes")
|
||||||
|
InputBool("Notification.AnimeFinished", user.Settings().Notification.AnimeFinished, "Finished anime series", "Notifications about finished anime series")
|
||||||
|
InputBool("Notification.NewFollowers", user.Settings().Notification.NewFollowers, "New followers", "Notifications about new followers")
|
||||||
|
|
||||||
|
.widget.mountable(data-api="/api/settings/" + user.ID)
|
||||||
|
h3.widget-title
|
||||||
|
Icon("heart")
|
||||||
|
span Likes
|
||||||
|
|
||||||
|
InputBool("Notification.ForumLikes", user.Settings().Notification.ForumLikes, "Forum post likes", "Notifications about forum post likes")
|
||||||
|
InputBool("Notification.SoundTrackLikes", user.Settings().Notification.SoundTrackLikes, "Soundtrack likes", "Notifications about soundtrack likes")
|
||||||
|
//- InputBool("Notification.GroupPostLikes", user.Settings().Notification.GroupPostLikes, "Group post likes", "Notifications about group post likes")
|
||||||
|
InputBool("Notification.QuoteLikes", user.Settings().Notification.QuoteLikes, "Quote likes", "Notifications about quote likes")
|
||||||
|
|
||||||
component SettingsApps(user *arn.User)
|
component SettingsApps(user *arn.User)
|
||||||
SettingsTabs
|
SettingsTabs
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/animenotifier/arn"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
defer arn.Node.Close()
|
||||||
|
|
||||||
|
for user := range arn.StreamUsers() {
|
||||||
|
settings := user.Settings()
|
||||||
|
settings.Notification = arn.DefaultNotificationSettings()
|
||||||
|
settings.Save()
|
||||||
|
}
|
||||||
|
}
|
@ -2,14 +2,18 @@ import { AnimeNotifier } from "../AnimeNotifier"
|
|||||||
|
|
||||||
// Enable notifications
|
// Enable notifications
|
||||||
export async function enableNotifications(arn: AnimeNotifier, button: HTMLElement) {
|
export async function enableNotifications(arn: AnimeNotifier, button: HTMLElement) {
|
||||||
|
arn.statusMessage.showInfo("Enabling push notifications...")
|
||||||
await arn.pushManager.subscribe(arn.user.dataset.id)
|
await arn.pushManager.subscribe(arn.user.dataset.id)
|
||||||
arn.updatePushUI()
|
arn.updatePushUI()
|
||||||
|
arn.statusMessage.showInfo("Enabled push notifications for this device.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable notifications
|
// Disable notifications
|
||||||
export async function disableNotifications(arn: AnimeNotifier, button: HTMLElement) {
|
export async function disableNotifications(arn: AnimeNotifier, button: HTMLElement) {
|
||||||
|
arn.statusMessage.showInfo("Disabling push notifications...")
|
||||||
await arn.pushManager.unsubscribe(arn.user.dataset.id)
|
await arn.pushManager.unsubscribe(arn.user.dataset.id)
|
||||||
arn.updatePushUI()
|
arn.updatePushUI()
|
||||||
|
arn.statusMessage.showInfo("Disabled push notifications for this device.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test notification
|
// Test notification
|
||||||
|
@ -48,6 +48,52 @@ export function save(arn: AnimeNotifier, input: HTMLElement) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable (bool field)
|
||||||
|
export async function enable(arn: AnimeNotifier, button: HTMLButtonElement) {
|
||||||
|
let obj = {}
|
||||||
|
let apiEndpoint = arn.findAPIEndpoint(button)
|
||||||
|
|
||||||
|
obj[button.dataset.field] = true
|
||||||
|
button.disabled = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Update boolean value
|
||||||
|
await arn.post(apiEndpoint, obj)
|
||||||
|
|
||||||
|
// Reload content
|
||||||
|
arn.reloadContent()
|
||||||
|
|
||||||
|
arn.statusMessage.showInfo("Enabled: " + button.title)
|
||||||
|
} catch(err) {
|
||||||
|
arn.statusMessage.showError(err)
|
||||||
|
} finally {
|
||||||
|
button.disabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable (bool field)
|
||||||
|
export async function disable(arn: AnimeNotifier, button: HTMLButtonElement) {
|
||||||
|
let obj = {}
|
||||||
|
let apiEndpoint = arn.findAPIEndpoint(button)
|
||||||
|
|
||||||
|
obj[button.dataset.field] = false
|
||||||
|
button.disabled = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Update boolean value
|
||||||
|
await arn.post(apiEndpoint, obj)
|
||||||
|
|
||||||
|
// Reload content
|
||||||
|
arn.reloadContent()
|
||||||
|
|
||||||
|
arn.statusMessage.showInfo("Disabled: " + button.title)
|
||||||
|
} catch(err) {
|
||||||
|
arn.statusMessage.showError(err)
|
||||||
|
} finally {
|
||||||
|
button.disabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Append new element to array
|
// Append new element to array
|
||||||
export function arrayAppend(arn: AnimeNotifier, element: HTMLElement) {
|
export function arrayAppend(arn: AnimeNotifier, element: HTMLElement) {
|
||||||
let field = element.dataset.field
|
let field = element.dataset.field
|
||||||
|
@ -312,8 +312,8 @@ export class AnimeNotifier {
|
|||||||
let testButton = this.app.find("test-notification") as HTMLButtonElement
|
let testButton = this.app.find("test-notification") as HTMLButtonElement
|
||||||
|
|
||||||
if(!this.pushManager.pushSupported) {
|
if(!this.pushManager.pushSupported) {
|
||||||
enableButton.style.display = "none"
|
enableButton.classList.add("hidden")
|
||||||
disableButton.style.display = "none"
|
disableButton.classList.add("hidden")
|
||||||
testButton.innerHTML = "Your browser doesn't support push notifications!"
|
testButton.innerHTML = "Your browser doesn't support push notifications!"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -321,11 +321,11 @@ export class AnimeNotifier {
|
|||||||
let subscription = await this.pushManager.subscription()
|
let subscription = await this.pushManager.subscription()
|
||||||
|
|
||||||
if(subscription) {
|
if(subscription) {
|
||||||
enableButton.style.display = "none"
|
enableButton.classList.add("hidden")
|
||||||
disableButton.style.display = "flex"
|
disableButton.classList.remove("hidden")
|
||||||
} else {
|
} else {
|
||||||
enableButton.style.display = "flex"
|
enableButton.classList.remove("hidden")
|
||||||
disableButton.style.display = "none"
|
disableButton.classList.add("hidden")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user