Browse Source

adjust the notification-subscription objects to try and send correct info

pull/112/head
Trent Larson 8 months ago
parent
commit
2ca33bb9eb
  1. 17
      src/App.vue
  2. 14
      src/libs/util.ts

17
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 { DEFAULT_PUSH_SERVER, NotificationIface } from "@/constants/app";
import { db } from "@/db/index"; import { db } from "@/db/index";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; 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); hourNum + Math.round(new Date().getTimezoneOffset() / 60);
const finalUtcHour = (utcHour + (utcHour < 0 ? 24 : 0)) % 24; const finalUtcHour = (utcHour + (utcHour < 0 ? 24 : 0)) % 24;
// This ignore commentary is because I'm adding non-standard stuff to the subscription object. const subscriptionWithTime: PushSubscriptionWithTime = {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const subscriptionWithTime = {
notifyTime: { utcHour: finalUtcHour }, notifyTime: { utcHour: finalUtcHour },
...subscription, ...subscription.toJSON(),
}; };
this.sendSubscriptionToServer(subscriptionWithTime); await this.sendSubscriptionToServer(subscriptionWithTime);
return subscription; return subscriptionWithTime;
} else { } else {
throw new Error("Subscription object is not available."); throw new Error("Subscription object is not available.");
} }
@ -665,7 +666,7 @@ export default class App extends Vue {
} }
private sendSubscriptionToServer( private sendSubscriptionToServer(
subscription: PushSubscription, subscription: PushSubscriptionWithTime,
): Promise<void> { ): Promise<void> {
console.log("About to send subscription...", subscription); console.log("About to send subscription...", subscription);
return fetch("/web-push/subscribe", { return fetch("/web-push/subscribe", {

14
src/libs/util.ts

@ -13,7 +13,7 @@ import { GenericServerRecord, containsHiddenDid } from "@/libs/endorserServer";
import * as serverUtil from "@/libs/endorserServer"; import * as serverUtil from "@/libs/endorserServer";
// eslint-disable-next-line @typescript-eslint/no-var-requires // eslint-disable-next-line @typescript-eslint/no-var-requires
const Buffer = require("buffer/").Buffer; //const Buffer = require("buffer/").Buffer;
export const PRIVACY_MESSAGE = 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."; "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<string> => {
}; };
export const sendTestThroughPushServer = async ( export const sendTestThroughPushServer = async (
subscription: PushSubscription, subscription: PushSubscriptionJSON,
skipFilter: boolean, skipFilter: boolean,
): Promise<AxiosResponse> => { ): Promise<AxiosResponse> => {
await db.open(); 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 // 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"; const DIRECT_PUSH_TITLE = "DIRECT_NOTIFICATION";
/** remove if the PushSubscriptionJSON approach works
*
const auth = Buffer.from(subscription.getKey("auth")); const auth = Buffer.from(subscription.getKey("auth"));
const authB64 = auth const authB64 = auth
.toString("base64") .toString("base64")
@ -278,6 +280,14 @@ export const sendTestThroughPushServer = async (
skipFilter ? "un" : "" skipFilter ? "un" : ""
}filtered.`, }filtered.`,
title: skipFilter ? DIRECT_PUSH_TITLE : "Your Web Push", 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); console.log("Sending a test web push message:", newPayload);
const payloadStr = JSON.stringify(newPayload); const payloadStr = JSON.stringify(newPayload);

Loading…
Cancel
Save