2021-03-14 02:31:17 +01:00
|
|
|
<div class="generic-instance-settings">
|
2018-10-28 23:28:22 +01:00
|
|
|
{#if pushNotificationsSupport === false}
|
2020-11-29 23:13:27 +01:00
|
|
|
<p>{intl.browserDoesNotSupportPush}</p>
|
2018-10-28 23:28:22 +01:00
|
|
|
{:elseif $notificationPermission === "denied"}
|
2020-11-29 23:13:27 +01:00
|
|
|
<p role="alert">{intl.deniedPush}</p>
|
2019-06-20 08:00:27 +02:00
|
|
|
{:elseif $loggedInInstancesInOrder.length > 1}
|
2020-11-29 23:13:27 +01:00
|
|
|
<p>{intl.pushNotificationsNote}</p>
|
2018-10-28 23:28:22 +01:00
|
|
|
{/if}
|
2019-05-26 00:20:09 +02:00
|
|
|
<form id="push-notification-settings"
|
|
|
|
disabled="{!pushNotificationsSupport}"
|
|
|
|
ref:form
|
2020-11-29 23:13:27 +01:00
|
|
|
aria-label="{intl.pushSettings}">
|
2019-05-26 00:20:09 +02:00
|
|
|
{#each options as option, i (option.key)}
|
|
|
|
{#if i > 0}
|
|
|
|
<br>
|
|
|
|
{/if}
|
|
|
|
<input type="checkbox"
|
|
|
|
id="push-notifications-{option.key}"
|
|
|
|
name="{option.key}"
|
|
|
|
disabled="{!pushNotificationsSupport}"
|
|
|
|
on:change="onPushSettingsChange(event)">
|
|
|
|
<label for="push-notifications-{option.key}">{option.label}</label>
|
|
|
|
{/each}
|
2018-10-28 23:28:22 +01:00
|
|
|
</form>
|
|
|
|
</div>
|
2021-03-14 02:31:17 +01:00
|
|
|
<GenericInstanceSettingsStyle/>
|
2018-10-28 23:28:22 +01:00
|
|
|
<style>
|
2019-05-26 00:20:09 +02:00
|
|
|
form[disabled="true"] {
|
2018-10-28 23:28:22 +01:00
|
|
|
opacity: 0.5;
|
|
|
|
}
|
2019-05-26 00:20:09 +02:00
|
|
|
p {
|
|
|
|
margin: 0 0 10px 0;
|
2018-10-28 23:28:22 +01:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
2021-03-14 02:31:17 +01:00
|
|
|
import GenericInstanceSettingsStyle from './GenericInstanceSettingsStyle.html'
|
2018-10-28 23:28:22 +01:00
|
|
|
import { store } from '../../../_store/store'
|
2019-10-30 02:58:49 +01:00
|
|
|
import { importShowTextConfirmationDialog } from '../../dialog/asyncDialogs/importShowTextConfirmationDialog.js'
|
2018-10-28 23:28:22 +01:00
|
|
|
import { logOutOfInstance } from '../../../_actions/instances'
|
|
|
|
import { updatePushSubscriptionForInstance, updateAlerts } from '../../../_actions/pushSubscription'
|
2018-12-23 00:37:51 +01:00
|
|
|
import { toast } from '../../toast/toast'
|
2019-05-25 22:21:17 +02:00
|
|
|
import { get } from '../../../_utils/lodash-lite'
|
2020-11-29 23:13:27 +01:00
|
|
|
import { formatIntl } from '../../../_utils/formatIntl'
|
2018-10-28 23:28:22 +01:00
|
|
|
|
|
|
|
export default {
|
|
|
|
async oncreate () {
|
2019-08-03 22:49:37 +02:00
|
|
|
const { instanceName, options } = this.get()
|
2018-10-28 23:28:22 +01:00
|
|
|
await updatePushSubscriptionForInstance(instanceName)
|
|
|
|
|
2019-05-26 00:20:09 +02:00
|
|
|
const { form } = this.refs
|
2019-06-20 08:00:27 +02:00
|
|
|
const pushSubscription = this.store.getInstanceData(instanceName, 'pushSubscriptions')
|
2018-10-28 23:28:22 +01:00
|
|
|
|
2019-08-03 22:49:37 +02:00
|
|
|
for (const { key } of options) {
|
2019-05-26 00:20:09 +02:00
|
|
|
form.elements[key].checked = get(pushSubscription, ['alerts', key])
|
|
|
|
}
|
2018-10-28 23:28:22 +01:00
|
|
|
},
|
|
|
|
store: () => store,
|
2019-05-26 00:20:09 +02:00
|
|
|
data: () => ({
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
key: 'follow',
|
2020-11-29 23:13:27 +01:00
|
|
|
label: 'intl.newFollowers'
|
2019-05-26 00:20:09 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'favourite',
|
2020-11-29 23:13:27 +01:00
|
|
|
label: 'intl.favorites'
|
2019-05-26 00:20:09 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'reblog',
|
2020-11-29 23:13:27 +01:00
|
|
|
label: 'intl.reblogs'
|
2019-05-26 00:20:09 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'mention',
|
2020-11-29 23:13:27 +01:00
|
|
|
label: 'intl.mentions'
|
2019-05-26 00:20:09 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'poll',
|
2020-11-29 23:13:27 +01:00
|
|
|
label: 'intl.pollResults'
|
2019-05-26 00:20:09 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}),
|
2018-10-28 23:28:22 +01:00
|
|
|
computed: {
|
|
|
|
pushNotificationsSupport: ({ $pushNotificationsSupport }) => $pushNotificationsSupport
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async onPushSettingsChange (e) {
|
2019-05-26 00:20:09 +02:00
|
|
|
const { instanceName, options } = this.get()
|
|
|
|
const { form } = this.refs
|
|
|
|
const alerts = {}
|
|
|
|
|
2019-08-03 22:49:37 +02:00
|
|
|
for (const { key } of options) {
|
2019-05-26 00:20:09 +02:00
|
|
|
alerts[key] = form.elements[key].checked
|
2018-10-28 23:28:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await updateAlerts(instanceName, alerts)
|
|
|
|
} catch (err) {
|
|
|
|
e.target.checked = !e.target.checked
|
|
|
|
|
|
|
|
// TODO: Better way to detect missing authorization scope
|
|
|
|
if (err.message.startsWith('403:')) {
|
2019-08-03 22:49:37 +02:00
|
|
|
const showTextConfirmationDialog = await importShowTextConfirmationDialog()
|
2019-02-19 00:43:41 +01:00
|
|
|
showTextConfirmationDialog({
|
2020-11-29 23:13:27 +01:00
|
|
|
text: formatIntl('intl.needToReauthenticate', { instance: instanceName })
|
2019-02-19 00:43:41 +01:00
|
|
|
}).on('positive', () => {
|
|
|
|
/* no await */ logOutOfInstance(instanceName)
|
2018-10-28 23:28:22 +01:00
|
|
|
})
|
|
|
|
} else {
|
2020-11-29 23:13:27 +01:00
|
|
|
toast.say(formatIntl('intl.failedToUpdatePush', {
|
|
|
|
error: err.message || ''
|
|
|
|
}))
|
2018-10-28 23:28:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-14 02:31:17 +01:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
GenericInstanceSettingsStyle
|
2018-10-28 23:28:22 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-23 00:37:51 +01:00
|
|
|
</script>
|