From 2ca33bb9ebed50205caecb809b497420daadf3a8 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Tue, 2 Apr 2024 19:18:31 -0600 Subject: [PATCH] adjust the notification-subscription objects to try and send correct info --- src/App.vue | 17 +++++++++-------- src/libs/util.ts | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/App.vue b/src/App.vue index e133ab1d..3d273212 100644 --- a/src/App.vue +++ b/src/App.vue @@ -345,6 +345,10 @@ interface VapidResponse { }; } +interface PushSubscriptionWithTime extends PushSubscriptionJSON { + notifyTime: { utcHour: number }; +} + import { DEFAULT_PUSH_SERVER, NotificationIface } from "@/constants/app"; import { db } from "@/db/index"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; @@ -561,15 +565,12 @@ export default class App extends Vue { hourNum + Math.round(new Date().getTimezoneOffset() / 60); const finalUtcHour = (utcHour + (utcHour < 0 ? 24 : 0)) % 24; - // This ignore commentary is because I'm adding non-standard stuff to the subscription object. - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - const subscriptionWithTime = { + const subscriptionWithTime: PushSubscriptionWithTime = { notifyTime: { utcHour: finalUtcHour }, - ...subscription, + ...subscription.toJSON(), }; - this.sendSubscriptionToServer(subscriptionWithTime); - return subscription; + await this.sendSubscriptionToServer(subscriptionWithTime); + return subscriptionWithTime; } else { throw new Error("Subscription object is not available."); } @@ -665,7 +666,7 @@ export default class App extends Vue { } private sendSubscriptionToServer( - subscription: PushSubscription, + subscription: PushSubscriptionWithTime, ): Promise { console.log("About to send subscription...", subscription); return fetch("/web-push/subscribe", { diff --git a/src/libs/util.ts b/src/libs/util.ts index 7c69b783..8a25ff68 100644 --- a/src/libs/util.ts +++ b/src/libs/util.ts @@ -13,7 +13,7 @@ import { GenericServerRecord, containsHiddenDid } from "@/libs/endorserServer"; import * as serverUtil from "@/libs/endorserServer"; // eslint-disable-next-line @typescript-eslint/no-var-requires -const Buffer = require("buffer/").Buffer; +//const Buffer = require("buffer/").Buffer; export const PRIVACY_MESSAGE = "The data you send be visible to the world -- except: your IDs and the IDs of anyone you tag will stay private, only visible to those you allow."; @@ -241,7 +241,7 @@ export const generateSaveAndActivateIdentity = async (): Promise => { }; export const sendTestThroughPushServer = async ( - subscription: PushSubscription, + subscription: PushSubscriptionJSON, skipFilter: boolean, ): Promise => { await db.open(); @@ -256,6 +256,8 @@ export const sendTestThroughPushServer = async ( // Use something other than "Daily Update" https://gitea.anomalistdesign.com/trent_larson/py-push-server/src/commit/3c0e196c11bc98060ec5934e99e7dbd591b5da4d/app.py#L213 const DIRECT_PUSH_TITLE = "DIRECT_NOTIFICATION"; + /** remove if the PushSubscriptionJSON approach works + * const auth = Buffer.from(subscription.getKey("auth")); const authB64 = auth .toString("base64") @@ -278,6 +280,14 @@ export const sendTestThroughPushServer = async ( skipFilter ? "un" : "" }filtered.`, title: skipFilter ? DIRECT_PUSH_TITLE : "Your Web Push", + }; + * + **/ + const newPayload = { + // eslint-disable-next-line prettier/prettier + message: `Test, where you will see this message ${ skipFilter ? "un" : "" }filtered.`, + title: skipFilter ? DIRECT_PUSH_TITLE : "Your Web Push", + ...subscription, }; console.log("Sending a test web push message:", newPayload); const payloadStr = JSON.stringify(newPayload);