@notificationapi/react 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as Q } from "react/jsx-runtime";
|
|
2
|
-
import { useState as I, useCallback as m, useMemo as X, useRef as U, useEffect as
|
|
2
|
+
import { useState as I, useCallback as m, useMemo as X, useRef as U, useEffect as y, useContext as Y } from "react";
|
|
3
3
|
import { NotificationAPIContext as H } from "./context.js";
|
|
4
4
|
const Z = async (e, c, i, a, f, b, h) => {
|
|
5
5
|
const l = ee(a, f, b), g = await fetch(
|
|
@@ -173,7 +173,7 @@ const Z = async (e, c, i, a, f, b, h) => {
|
|
|
173
173
|
i.playSoundOnNewNotification && new Audio(i.newNotificationSoundPath).play().catch((s) => {
|
|
174
174
|
console.log("Failed to play new notification sound:", s);
|
|
175
175
|
});
|
|
176
|
-
}, [i.newNotificationSoundPath, i.playSoundOnNewNotification]),
|
|
176
|
+
}, [i.newNotificationSoundPath, i.playSoundOnNewNotification]), P = m((t) => {
|
|
177
177
|
const s = (/* @__PURE__ */ new Date()).toISOString();
|
|
178
178
|
f((n) => (t = Array.isArray(t) ? t : [], t = t.filter((d) => {
|
|
179
179
|
const p = d.expDate && new Date(d.expDate).toISOString() > s, D = new Date(d.date).getTime() > new Date(s).getTime() + 1e3;
|
|
@@ -188,7 +188,7 @@ const Z = async (e, c, i, a, f, b, h) => {
|
|
|
188
188
|
userId: i.user.id,
|
|
189
189
|
hashedUserId: i.hashedUserId,
|
|
190
190
|
onNewInAppNotifications: (s) => {
|
|
191
|
-
W(),
|
|
191
|
+
W(), P(s);
|
|
192
192
|
},
|
|
193
193
|
host: i.apiURL,
|
|
194
194
|
websocketHost: i.wsURL
|
|
@@ -203,7 +203,7 @@ const Z = async (e, c, i, a, f, b, h) => {
|
|
|
203
203
|
i.user.email,
|
|
204
204
|
i.user.number,
|
|
205
205
|
i.hashedUserId,
|
|
206
|
-
|
|
206
|
+
P,
|
|
207
207
|
W,
|
|
208
208
|
e.client,
|
|
209
209
|
i.apiURL,
|
|
@@ -211,11 +211,11 @@ const Z = async (e, c, i, a, f, b, h) => {
|
|
|
211
211
|
]), x = m(
|
|
212
212
|
async (t, s) => {
|
|
213
213
|
const n = await u.rest.getNotifications(t, s);
|
|
214
|
-
T(n.oldestReceived), C(n.couldLoadMore),
|
|
214
|
+
T(n.oldestReceived), C(n.couldLoadMore), P(n.notifications);
|
|
215
215
|
},
|
|
216
|
-
[
|
|
216
|
+
[P, u.rest]
|
|
217
217
|
), E = U(A), R = U(w), $ = U(k);
|
|
218
|
-
|
|
218
|
+
y(() => {
|
|
219
219
|
E.current = A, R.current = w, $.current = k;
|
|
220
220
|
}, [A, w, k]);
|
|
221
221
|
const O = m(
|
|
@@ -330,17 +330,19 @@ const Z = async (e, c, i, a, f, b, h) => {
|
|
|
330
330
|
i.customServiceWorkerPath,
|
|
331
331
|
l == null ? void 0 : l.userAccountMetadata.environmentVapidPublicKey
|
|
332
332
|
]);
|
|
333
|
-
|
|
333
|
+
y(() => {
|
|
334
334
|
f([]), S(!1), h(void 0), T((/* @__PURE__ */ new Date()).toISOString()), C(!0), O(!0), u.openWebSocket(), u.getPreferences().then((t) => {
|
|
335
335
|
h(t);
|
|
336
336
|
});
|
|
337
|
-
}, [u, O, M]),
|
|
338
|
-
|
|
339
|
-
g(t), N(t.userAccountMetadata.hasWebPushEnabled);
|
|
340
|
-
})
|
|
337
|
+
}, [u, O, M]), y(() => {
|
|
338
|
+
u.getUserAccountMetadata().then((t) => {
|
|
339
|
+
g(t), F && "Notification" in window && typeof Notification.requestPermission == "function" ? Notification.permission !== "default" && N(!1) : N(t.userAccountMetadata.hasWebPushEnabled);
|
|
340
|
+
});
|
|
341
|
+
}, [u]), y(() => {
|
|
342
|
+
v === "AUTOMATIC" && N(
|
|
341
343
|
localStorage.getItem("hideWebPushOptInMessage") !== "true"
|
|
342
344
|
);
|
|
343
|
-
}, [
|
|
345
|
+
}, [v]), y(() => {
|
|
344
346
|
L && M();
|
|
345
347
|
}, [L, M]);
|
|
346
348
|
const z = {
|