2018-04-02 07:34:16 +02:00
|
|
|
import AnimeNotifier from "../AnimeNotifier"
|
2017-10-17 11:27:15 +02:00
|
|
|
|
|
|
|
// Enable notifications
|
2019-04-22 18:06:50 +09:00
|
|
|
export async function enableNotifications(arn: AnimeNotifier, _: HTMLElement) {
|
2019-11-18 11:04:13 +09:00
|
|
|
if(!arn.user) {
|
2019-04-19 23:34:49 +09:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-03-29 12:14:46 +02:00
|
|
|
arn.statusMessage.showInfo("Enabling instant notifications...")
|
2019-11-18 11:04:13 +09:00
|
|
|
await arn.pushManager.subscribe(arn.user.id)
|
2017-10-17 11:27:15 +02:00
|
|
|
arn.updatePushUI()
|
2018-03-29 12:14:46 +02:00
|
|
|
arn.statusMessage.showInfo("Enabled instant notifications for this device.")
|
2017-10-17 11:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disable notifications
|
2019-04-22 18:06:50 +09:00
|
|
|
export async function disableNotifications(arn: AnimeNotifier, _: HTMLElement) {
|
2019-11-18 11:04:13 +09:00
|
|
|
if(!arn.user) {
|
2019-04-19 23:34:49 +09:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-03-29 12:14:46 +02:00
|
|
|
arn.statusMessage.showInfo("Disabling instant notifications...")
|
2019-11-18 11:04:13 +09:00
|
|
|
await arn.pushManager.unsubscribe(arn.user.id)
|
2017-10-17 11:27:15 +02:00
|
|
|
arn.updatePushUI()
|
2018-03-29 12:14:46 +02:00
|
|
|
arn.statusMessage.showInfo("Disabled instant notifications for this device.")
|
2017-10-17 11:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test notification
|
2018-02-28 23:26:06 +01:00
|
|
|
export async function testNotification(arn: AnimeNotifier) {
|
2018-04-18 12:33:19 +02:00
|
|
|
arn.statusMessage.showInfo("Sending test notification...this might take a few seconds...")
|
|
|
|
|
2018-02-28 23:26:06 +01:00
|
|
|
await fetch("/api/test/notification", {
|
2017-10-17 11:27:15 +02:00
|
|
|
credentials: "same-origin"
|
|
|
|
})
|
2018-03-01 00:06:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark notifications as seen
|
|
|
|
export async function markNotificationsAsSeen(arn: AnimeNotifier) {
|
|
|
|
await fetch("/api/mark/notifications/seen", {
|
|
|
|
credentials: "same-origin"
|
|
|
|
})
|
|
|
|
|
|
|
|
// Update notifications
|
|
|
|
arn.reloadContent()
|
2019-11-17 18:44:30 +09:00
|
|
|
}
|