diff --git a/jellyseerr-api.yml b/jellyseerr-api.yml
index 8437056f8..65bb54951 100644
--- a/jellyseerr-api.yml
+++ b/jellyseerr-api.yml
@@ -4107,7 +4107,7 @@ paths:
type: string
userAgent:
type: string
- /user/{userId}/pushSubscription/{key}:
+ /user/{userId}/pushSubscription/{endpoint}:
get:
summary: Get web push notification settings for a user
description: |
@@ -4121,7 +4121,7 @@ paths:
schema:
type: number
- in: path
- name: key
+ name: endpoint
required: true
schema:
type: string
@@ -4153,7 +4153,7 @@ paths:
schema:
type: number
- in: path
- name: key
+ name: endpoint
required: true
schema:
type: string
diff --git a/server/routes/user/index.ts b/server/routes/user/index.ts
index 028b26e62..f817a9cb3 100644
--- a/server/routes/user/index.ts
+++ b/server/routes/user/index.ts
@@ -240,8 +240,8 @@ router.get<{ userId: number }>(
}
);
-router.get<{ userId: number; key: string }>(
- '/:userId/pushSubscription/:key',
+router.get<{ userId: number; endpoint: string }>(
+ '/:userId/pushSubscription/:endpoint',
async (req, res, next) => {
try {
const userPushSubRepository = getRepository(UserPushSubscription);
@@ -252,7 +252,7 @@ router.get<{ userId: number; key: string }>(
},
where: {
user: { id: req.params.userId },
- p256dh: req.params.key,
+ endpoint: req.params.endpoint,
},
});
@@ -263,8 +263,8 @@ router.get<{ userId: number; key: string }>(
}
);
-router.delete<{ userId: number; key: string }>(
- '/:userId/pushSubscription/:key',
+router.delete<{ userId: number; endpoint: string }>(
+ '/:userId/pushSubscription/:endpoint',
async (req, res, next) => {
try {
const userPushSubRepository = getRepository(UserPushSubscription);
@@ -275,7 +275,7 @@ router.delete<{ userId: number; key: string }>(
},
where: {
user: { id: req.params.userId },
- p256dh: req.params.key,
+ endpoint: req.params.endpoint,
},
});
@@ -284,7 +284,7 @@ router.delete<{ userId: number; key: string }>(
} catch (e) {
logger.error('Something went wrong deleting the user push subcription', {
label: 'API',
- key: req.params.key,
+ endpoint: req.params.endpoint,
errorMessage: e.message,
});
return next({
diff --git a/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/DeviceItem.tsx b/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/DeviceItem.tsx
index 59da71093..7fdefa4a5 100644
--- a/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/DeviceItem.tsx
+++ b/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/DeviceItem.tsx
@@ -33,13 +33,14 @@ const messages = defineMessages(
const DeviceItem = ({ disablePushNotifications, device }: DeviceItemProps) => {
const intl = useIntl();
+ const parsedUserAgent = UAParser(device.userAgent);
return (
- {UAParser(device.userAgent).device.type === 'mobile' ? (
+ {parsedUserAgent.device.type === 'mobile' ? (
) : (
@@ -56,8 +57,8 @@ const DeviceItem = ({ disablePushNotifications, device }: DeviceItemProps) => {
: 'N/A'}
- {device.userAgent
- ? UAParser(device.userAgent).device.model
+ {device.userAgent && parsedUserAgent.device.model
+ ? parsedUserAgent.device.model
: intl.formatMessage(messages.unknown)}
@@ -68,7 +69,7 @@ const DeviceItem = ({ disablePushNotifications, device }: DeviceItemProps) => {
{intl.formatMessage(messages.operatingsystem)}
- {device.userAgent ? UAParser(device.userAgent).os.name : 'N/A'}
+ {device.userAgent ? parsedUserAgent.os.name : 'N/A'}
@@ -76,9 +77,7 @@ const DeviceItem = ({ disablePushNotifications, device }: DeviceItemProps) => {
{intl.formatMessage(messages.browser)}
- {device.userAgent
- ? UAParser(device.userAgent).browser.name
- : 'N/A'}
+ {device.userAgent ? parsedUserAgent.browser.name : 'N/A'}
@@ -86,16 +85,14 @@ const DeviceItem = ({ disablePushNotifications, device }: DeviceItemProps) => {
{intl.formatMessage(messages.engine)}
- {device.userAgent
- ? UAParser(device.userAgent).engine.name
- : 'N/A'}
+ {device.userAgent ? parsedUserAgent.engine.name : 'N/A'}
disablePushNotifications(device.p256dh)}
+ onClick={() => disablePushNotifications(device.endpoint)}
confirmText={intl.formatMessage(globalMessages.areyousure)}
className="w-full"
>
diff --git a/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx b/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx
index feb542147..11e082901 100644
--- a/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx
+++ b/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx
@@ -113,7 +113,7 @@ const UserWebPushSettings = () => {
// Unsubscribes from the push manager
// Deletes/disables corresponding push subscription from database
- const disablePushNotifications = async (p256dh?: string) => {
+ const disablePushNotifications = async (endpoint?: string) => {
if ('serviceWorker' in navigator && user?.id) {
navigator.serviceWorker.getRegistration('/sw.js').then((registration) => {
registration?.pushManager
@@ -122,17 +122,21 @@ const UserWebPushSettings = () => {
const parsedSub = JSON.parse(JSON.stringify(subscription));
await axios.delete(
- `/api/v1/user/${user?.id}/pushSubscription/${
- p256dh ? p256dh : parsedSub.keys.p256dh
- }`
+ `/api/v1/user/${user.id}/pushSubscription/${encodeURIComponent(
+ endpoint ?? parsedSub.endpoint
+ )}`
);
- if (subscription && (p256dh === parsedSub.keys.p256dh || !p256dh)) {
+
+ if (
+ subscription &&
+ (endpoint === parsedSub.endpoint || !endpoint)
+ ) {
subscription.unsubscribe();
setWebPushEnabled(false);
}
addToast(
intl.formatMessage(
- p256dh
+ endpoint
? messages.subscriptiondeleted
: messages.webpushhasbeendisabled
),
@@ -145,7 +149,7 @@ const UserWebPushSettings = () => {
.catch(function () {
addToast(
intl.formatMessage(
- p256dh
+ endpoint
? messages.subscriptiondeleteerror
: messages.disablingwebpusherror
),
@@ -176,12 +180,17 @@ const UserWebPushSettings = () => {
const parsedKey = JSON.parse(JSON.stringify(subscription));
const currentUserPushSub =
await axios.get(
- `/api/v1/user/${user.id}/pushSubscription/${parsedKey.keys.p256dh}`
+ `/api/v1/user/${
+ user.id
+ }/pushSubscription/${encodeURIComponent(
+ parsedKey.endpoint
+ )}`
);
- if (currentUserPushSub.data.p256dh !== parsedKey.keys.p256dh) {
+ if (currentUserPushSub.data.endpoint !== parsedKey.endpoint) {
return;
}
+
setWebPushEnabled(true);
} else {
setWebPushEnabled(false);