Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: TypeError in notification list #8935

Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 41 additions & 37 deletions src/components/Notifications/NotificationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ export default function NotificationsList({

const handleSubscribeClick = () => {
const status = isSubscribed;
if (status === "NotSubscribed" || status === "SubscribedOnAnotherDevice") {
if (!navigator.serviceWorker) {
return;
}
if (["NotSubscribed", "SubscribedOnAnotherDevice"].includes(status)) {
subscribe();
} else {
unsubscribe();
Expand Down Expand Up @@ -296,43 +299,44 @@ export default function NotificationsList({

let manageResults: any = null;

const unsubscribe = () => {
navigator.serviceWorker.ready
.then(function (reg) {
setIsSubscribing(true);
reg.pushManager
.getSubscription()
.then(function (subscription) {
subscription
?.unsubscribe()
.then(async function (_successful) {
const data = {
pf_endpoint: "",
pf_p256dh: "",
pf_auth: "",
};

await request(routes.updateUserPnconfig, {
pathParams: { username: username },
body: data,
});

setIsSubscribed("NotSubscribed");
setIsSubscribing(false);
})
.catch(function (_e) {
Error({
msg: t("unsubscribe_failed"),
});
});
})
.catch(function (_e) {
Error({ msg: t("subscription_error") });
const unsubscribe = async () => {
try {
const reg = await navigator.serviceWorker.ready;

if (!reg.pushManager) return;

setIsSubscribing(true);

const subscription = await reg.pushManager.getSubscription();

if (subscription) {
try {
await subscription.unsubscribe();

const data = {
pf_endpoint: "",
pf_p256dh: "",
pf_auth: "",
};

await request(routes.updateUserPnconfig, {
pathParams: { username },
body: data,
});
})
.catch(function (_e) {
Sentry.captureException(_e);
});

setIsSubscribed("NotSubscribed");
AdityaJ2305 marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
Error({ msg: t("unsubscribe_failed") });
} finally {
setIsSubscribing(false);
}
} else {
setIsSubscribing(false);
}
} catch (e) {
Sentry.captureException(e);
Error({ msg: t("subscription_error") });
}
};

async function subscribe() {
Expand Down
Loading