finish separation of daily reminder message, bump version to 0.3.34

This commit is contained in:
2024-11-24 13:09:40 -07:00
parent 15e09c2d81
commit 2758af6e6e
15 changed files with 448 additions and 128 deletions

View File

@@ -238,6 +238,7 @@
</div>
</div>
</div>
<div
v-if="notification.type === 'notification-mute'"
class="absolute inset-0 h-screen flex flex-col items-center justify-center bg-slate-900/50"
@@ -277,6 +278,7 @@
</div>
</div>
</div>
<div
v-if="notification.type === 'notification-off'"
class="absolute inset-0 h-screen flex flex-col items-center justify-center bg-slate-900/50"
@@ -286,7 +288,7 @@
>
<div class="w-full px-6 py-6 text-slate-900 text-center">
<p class="text-lg mb-4">
Would you like to <b>turn off</b> notifications for this app?
Would you like to <b>turn off</b> this notification?
</p>
<button
@@ -296,7 +298,7 @@
"
class="block w-full text-center text-md font-bold uppercase bg-rose-600 text-white px-2 py-2 rounded-md mb-2"
>
Turn Off Notifications
Turn Off Notification
</button>
<button
@click="close(notification.id)"
@@ -318,9 +320,8 @@
<script lang="ts">
import { Vue, Component } from "vue-facing-decorator";
import { db, logConsoleAndDb } from "@/db/index";
import { logConsoleAndDb, retrieveSettingsForActiveAccount } from "@/db/index";
import { NotificationIface } from "./constants/app";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
@Component
export default class App extends Vue {
@@ -329,18 +330,29 @@ export default class App extends Vue {
stopAsking = false;
async turnOffNotifications(notification: NotificationIface) {
let subscription;
const pushProviderSuccess: boolean = await navigator.serviceWorker?.ready
let subscription: object | null = null;
let allGoingOff = false;
const settings = await retrieveSettingsForActiveAccount();
const notifyingNewActivity = !!settings?.notifyingNewActivityTime;
const notifyingReminder = !!settings?.notifyingReminderTime;
if (!notifyingNewActivity || !notifyingReminder) {
// the other notification is already off, so fully unsubscribe now
allGoingOff = true;
}
await navigator.serviceWorker?.ready
.then((registration) => {
return registration.pushManager.getSubscription();
})
.then((subscript: PushSubscription | null) => {
subscription = subscript;
.then(async (subscript: PushSubscription | null) => {
if (subscript) {
return subscript.unsubscribe();
subscription = subscript.toJSON();
if (allGoingOff) {
await subscript.unsubscribe();
}
} else {
logConsoleAndDb("Subscription object is not available.");
return false;
}
})
.catch((error) => {
@@ -348,15 +360,20 @@ export default class App extends Vue {
"Push provider server communication failed: " + JSON.stringify(error),
true,
);
return false;
});
const pushServerSuccess: boolean = await fetch("/web-push/unsubscribe", {
const serverSubscription = {
...subscription,
};
if (!allGoingOff) {
serverSubscription["notifyType"] = notification.title;
}
const pushServerSuccess = await fetch("/web-push/unsubscribe", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(subscription),
body: JSON.stringify(serverSubscription),
})
.then((response) => {
return response.ok;
@@ -370,34 +387,24 @@ export default class App extends Vue {
});
let message;
if (pushProviderSuccess === pushServerSuccess) {
message = "Both local and server notifications ";
if (pushProviderSuccess) {
message += "are off.";
} else {
message += "failed to turn off.";
}
if (pushServerSuccess) {
message = "Notification is off.";
} else {
message =
"Local unsubscribe " +
(pushProviderSuccess ? "succeeded" : "failed") +
" but server unsubscribe " +
(pushServerSuccess ? "succeeded" : "failed") +
".";
message = "Notification is still on. Try to turn it off again.";
}
this.$notify({
group: "alert",
type: "info",
title: "Finished",
text: message,
});
this.$notify(
{
group: "alert",
type: "info",
title: "Finished",
text: message,
},
5000,
);
await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, {
notifyingNewActivity: false,
});
if (notification.callback) {
notification.callback(pushProviderSuccess && pushServerSuccess);
// it's OK if the local notifications are still on (especially if the other notification is on)
notification.callback(pushServerSuccess);
}
}
}