2017-10-17 09:27:15 +00:00
|
|
|
import { AnimeNotifier } from "../AnimeNotifier"
|
|
|
|
|
|
|
|
// Enable notifications
|
|
|
|
export async function enableNotifications(arn: AnimeNotifier, button: HTMLElement) {
|
2018-03-15 20:08:30 +00:00
|
|
|
arn.statusMessage.showInfo("Enabling push notifications...")
|
2017-10-17 09:27:15 +00:00
|
|
|
await arn.pushManager.subscribe(arn.user.dataset.id)
|
|
|
|
arn.updatePushUI()
|
2018-03-15 20:08:30 +00:00
|
|
|
arn.statusMessage.showInfo("Enabled push notifications for this device.")
|
2017-10-17 09:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disable notifications
|
|
|
|
export async function disableNotifications(arn: AnimeNotifier, button: HTMLElement) {
|
2018-03-15 20:08:30 +00:00
|
|
|
arn.statusMessage.showInfo("Disabling push notifications...")
|
2017-10-17 09:27:15 +00:00
|
|
|
await arn.pushManager.unsubscribe(arn.user.dataset.id)
|
|
|
|
arn.updatePushUI()
|
2018-03-15 20:08:30 +00:00
|
|
|
arn.statusMessage.showInfo("Disabled push notifications for this device.")
|
2017-10-17 09:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test notification
|
2018-02-28 22:26:06 +00:00
|
|
|
export async function testNotification(arn: AnimeNotifier) {
|
|
|
|
await fetch("/api/test/notification", {
|
2017-10-17 09:27:15 +00:00
|
|
|
credentials: "same-origin"
|
|
|
|
})
|
2018-02-28 23:06:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark notifications as seen
|
|
|
|
export async function markNotificationsAsSeen(arn: AnimeNotifier) {
|
|
|
|
await fetch("/api/mark/notifications/seen", {
|
|
|
|
credentials: "same-origin"
|
|
|
|
})
|
|
|
|
|
|
|
|
// Update notification counter
|
|
|
|
arn.notificationManager.update()
|
|
|
|
|
|
|
|
// Update notifications
|
|
|
|
arn.reloadContent()
|
2017-10-17 09:27:15 +00:00
|
|
|
}
|