Skip to content

Commit

Permalink
Added Suggestions by codeRabbit
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaJ2305 committed Nov 6, 2024
1 parent 515c372 commit 7ae9711
Showing 1 changed file with 37 additions and 38 deletions.
75 changes: 37 additions & 38 deletions src/components/Notifications/NotificationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,45 +299,44 @@ export default function NotificationsList({

let manageResults: any = null;

const unsubscribe = () => {
navigator.serviceWorker.ready
.then(function (reg) {
if (reg.pushManager) {
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,
});

setIsSubscribed("NotSubscribed");
} catch (e) {
Error({ msg: t("unsubscribe_failed") });
} finally {
setIsSubscribing(false);
}
})
.catch(function (_e) {
Sentry.captureException(_e);
});
} else {
setIsSubscribing(false);
}
} catch (e) {
Sentry.captureException(e);
Error({ msg: t("subscription_error") });
}
};

async function subscribe() {
Expand Down

0 comments on commit 7ae9711

Please sign in to comment.