mirror of https://github.com/tooot-app/app
Should fix #692
This commit is contained in:
parent
5ec49739fc
commit
2a774a5516
|
@ -79,22 +79,20 @@ const TabMePush: React.FC = () => {
|
||||||
<MenuRow
|
<MenuRow
|
||||||
key={alert}
|
key={alert}
|
||||||
title={t(`me.push.${alert}.heading`)}
|
title={t(`me.push.${alert}.heading`)}
|
||||||
// switchDisabled={!pushEnabled || !push.global}
|
|
||||||
switchValue={push?.alerts[alert]}
|
switchValue={push?.alerts[alert]}
|
||||||
switchOnValueChange={async () => {
|
switchOnValueChange={async () => {
|
||||||
const alerts = { ...push?.alerts, [alert]: !push?.alerts[alert] }
|
const alerts = { ...push?.alerts, [alert]: !push?.alerts[alert] }
|
||||||
const body: { data: { alerts: { [key: string]: boolean } } } = {
|
|
||||||
data: { alerts: {} }
|
|
||||||
}
|
|
||||||
for (const [key, value] of Object.entries(alerts)) {
|
|
||||||
body.data.alerts[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
await apiInstance<Mastodon.PushSubscription>({
|
if (pushEnabled && push.global) {
|
||||||
method: 'put',
|
const body: { data: { alerts: Mastodon.PushSubscription['alerts'] } } = {
|
||||||
url: 'push/subscription',
|
data: { alerts }
|
||||||
body
|
}
|
||||||
})
|
await apiInstance<Mastodon.PushSubscription>({
|
||||||
|
method: 'put',
|
||||||
|
url: 'push/subscription',
|
||||||
|
body
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
setAccountStorage([{ key: 'push', value: { ...push, alerts } }])
|
setAccountStorage([{ key: 'push', value: { ...push, alerts } }])
|
||||||
}}
|
}}
|
||||||
|
@ -109,22 +107,22 @@ const TabMePush: React.FC = () => {
|
||||||
<MenuRow
|
<MenuRow
|
||||||
key={type}
|
key={type}
|
||||||
title={t(`me.push.${type}.heading`)}
|
title={t(`me.push.${type}.heading`)}
|
||||||
// switchDisabled={!pushEnabled || !push.global}
|
|
||||||
switchValue={push?.alerts[type]}
|
switchValue={push?.alerts[type]}
|
||||||
switchOnValueChange={async () => {
|
switchOnValueChange={async () => {
|
||||||
const alerts = { ...push?.alerts, [type]: !push?.alerts[type] }
|
const alerts = { ...push?.alerts, [type]: !push?.alerts[type] }
|
||||||
const body: { data: { alerts: { [key: string]: boolean } } } = {
|
|
||||||
data: { alerts: {} }
|
|
||||||
}
|
|
||||||
for (const [key, value] of Object.entries(alerts)) {
|
|
||||||
body.data.alerts[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
await apiInstance<Mastodon.PushSubscription>({
|
if (pushEnabled && push.global) {
|
||||||
method: 'put',
|
const body: {
|
||||||
url: 'push/subscription',
|
data: { alerts: Mastodon.PushSubscription['alerts'] }
|
||||||
body
|
} = {
|
||||||
})
|
data: { alerts }
|
||||||
|
}
|
||||||
|
await apiInstance<Mastodon.PushSubscription>({
|
||||||
|
method: 'put',
|
||||||
|
url: 'push/subscription',
|
||||||
|
body
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
setAccountStorage([{ key: 'push', value: { ...push, alerts } }])
|
setAccountStorage([{ key: 'push', value: { ...push, alerts } }])
|
||||||
}}
|
}}
|
||||||
|
@ -198,7 +196,10 @@ const TabMePush: React.FC = () => {
|
||||||
|
|
||||||
const endpoint = `https://${TOOOT_API_DOMAIN}/push/send/${pushPath}/${randomPath}`
|
const endpoint = `https://${TOOOT_API_DOMAIN}/push/send/${pushPath}/${randomPath}`
|
||||||
|
|
||||||
const body: { subscription: any; alerts: { [key: string]: boolean } } = {
|
const body: {
|
||||||
|
subscription: any
|
||||||
|
alerts: Mastodon.PushSubscription['alerts']
|
||||||
|
} = {
|
||||||
subscription: {
|
subscription: {
|
||||||
endpoint,
|
endpoint,
|
||||||
keys: {
|
keys: {
|
||||||
|
@ -207,10 +208,7 @@ const TabMePush: React.FC = () => {
|
||||||
auth: authKey
|
auth: authKey
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
alerts: {}
|
alerts: push.alerts
|
||||||
}
|
|
||||||
for (const [key, value] of Object.entries(push.alerts)) {
|
|
||||||
body.alerts[key] = value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await apiInstance<Mastodon.PushSubscription>({
|
const res = await apiInstance<Mastodon.PushSubscription>({
|
||||||
|
@ -226,6 +224,10 @@ const TabMePush: React.FC = () => {
|
||||||
message: t('me.push.missingServerKey.message'),
|
message: t('me.push.missingServerKey.message'),
|
||||||
description: t('me.push.missingServerKey.description')
|
description: t('me.push.missingServerKey.description')
|
||||||
})
|
})
|
||||||
|
await apiInstance({
|
||||||
|
method: 'delete',
|
||||||
|
url: 'push/subscription'
|
||||||
|
})
|
||||||
Sentry.setContext('Push server key', {
|
Sentry.setContext('Push server key', {
|
||||||
instance: domain,
|
instance: domain,
|
||||||
resBody: res.body
|
resBody: res.body
|
||||||
|
@ -242,6 +244,11 @@ const TabMePush: React.FC = () => {
|
||||||
serverKey: res.body.server_key,
|
serverKey: res.body.server_key,
|
||||||
auth: push.decode === false ? null : authKey
|
auth: push.decode === false ? null : authKey
|
||||||
}
|
}
|
||||||
|
}).catch(async () => {
|
||||||
|
await apiInstance({
|
||||||
|
method: 'delete',
|
||||||
|
url: 'push/subscription'
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
setAccountStorage([
|
setAccountStorage([
|
||||||
|
|
Loading…
Reference in New Issue