diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-09-29 11:29:54 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2023-09-29 11:29:54 +0900 |
| commit | b9da1415a50f6036350c6453d4a681b58bf17d1e (patch) | |
| tree | 06614d5be85f027890a969548ca816e6a36c8c78 /packages/frontend/src/components | |
| parent | .js (diff) | |
| download | misskey-b9da1415a50f6036350c6453d4a681b58bf17d1e.tar.gz misskey-b9da1415a50f6036350c6453d4a681b58bf17d1e.tar.bz2 misskey-b9da1415a50f6036350c6453d4a681b58bf17d1e.zip | |
feat: 通知の受信設定を強化
Diffstat (limited to 'packages/frontend/src/components')
3 files changed, 82 insertions, 100 deletions
diff --git a/packages/frontend/src/components/MkNotificationSelectWindow.vue b/packages/frontend/src/components/MkNotificationSelectWindow.vue new file mode 100644 index 0000000000..3d5a56975b --- /dev/null +++ b/packages/frontend/src/components/MkNotificationSelectWindow.vue @@ -0,0 +1,78 @@ +<!-- +SPDX-FileCopyrightText: syuilo and other misskey contributors +SPDX-License-Identifier: AGPL-3.0-only +--> + +<template> +<MkModalWindow + ref="dialog" + :width="400" + :height="450" + :withOkButton="true" + :okButtonDisabled="false" + @ok="ok()" + @close="dialog?.close()" + @closed="emit('closed')" +> + <template #header>{{ i18n.ts.notificationSetting }}</template> + + <MkSpacer :marginMin="20" :marginMax="28"> + <div class="_gaps_m"> + <MkInfo>{{ i18n.ts.notificationSettingDesc }}</MkInfo> + <div class="_buttons"> + <MkButton inline @click="disableAll">{{ i18n.ts.disableAll }}</MkButton> + <MkButton inline @click="enableAll">{{ i18n.ts.enableAll }}</MkButton> + </div> + <MkSwitch v-for="ntype in notificationTypes" :key="ntype" v-model="typesMap[ntype].value">{{ i18n.t(`_notification._types.${ntype}`) }}</MkSwitch> + </div> + </MkSpacer> +</MkModalWindow> +</template> + +<script lang="ts" setup> +import { ref, Ref } from 'vue'; +import MkSwitch from './MkSwitch.vue'; +import MkInfo from './MkInfo.vue'; +import MkButton from './MkButton.vue'; +import MkModalWindow from '@/components/MkModalWindow.vue'; +import { notificationTypes } from '@/const.js'; +import { i18n } from '@/i18n.js'; + +type TypesMap = Record<typeof notificationTypes[number], Ref<boolean>> + +const emit = defineEmits<{ + (ev: 'done', v: { excludeTypes: string[] }): void, + (ev: 'closed'): void, +}>(); + +const props = withDefaults(defineProps<{ + excludeTypes?: typeof notificationTypes[number][]; +}>(), { + excludeTypes: () => [], +}); + +const dialog = $shallowRef<InstanceType<typeof MkModalWindow>>(); + +const typesMap: TypesMap = notificationTypes.reduce((p, t) => ({ ...p, [t]: ref<boolean>(!props.excludeTypes.includes(t)) }), {} as any); + +function ok() { + emit('done', { + excludeTypes: (Object.keys(typesMap) as typeof notificationTypes[number][]) + .filter(type => !typesMap[type].value), + }); + + if (dialog) dialog.close(); +} + +function disableAll() { + for (const type of notificationTypes) { + typesMap[type].value = false; + } +} + +function enableAll() { + for (const type of notificationTypes) { + typesMap[type].value = true; + } +} +</script> diff --git a/packages/frontend/src/components/MkNotificationSettingWindow.vue b/packages/frontend/src/components/MkNotificationSettingWindow.vue deleted file mode 100644 index a25914b214..0000000000 --- a/packages/frontend/src/components/MkNotificationSettingWindow.vue +++ /dev/null @@ -1,95 +0,0 @@ -<!-- -SPDX-FileCopyrightText: syuilo and other misskey contributors -SPDX-License-Identifier: AGPL-3.0-only ---> - -<template> -<MkModalWindow - ref="dialog" - :width="400" - :height="450" - :withOkButton="true" - :okButtonDisabled="false" - @ok="ok()" - @close="dialog?.close()" - @closed="emit('closed')" -> - <template #header>{{ i18n.ts.notificationSetting }}</template> - - <MkSpacer :marginMin="20" :marginMax="28"> - <div class="_gaps_m"> - <template v-if="showGlobalToggle"> - <MkSwitch v-model="useGlobalSetting"> - {{ i18n.ts.useGlobalSetting }} - <template #caption>{{ i18n.ts.useGlobalSettingDesc }}</template> - </MkSwitch> - </template> - <template v-if="!useGlobalSetting"> - <MkInfo>{{ i18n.ts.notificationSettingDesc }}</MkInfo> - <div class="_buttons"> - <MkButton inline @click="disableAll">{{ i18n.ts.disableAll }}</MkButton> - <MkButton inline @click="enableAll">{{ i18n.ts.enableAll }}</MkButton> - </div> - <MkSwitch v-for="ntype in notificationTypes" :key="ntype" v-model="typesMap[ntype].value">{{ i18n.t(`_notification._types.${ntype}`) }}</MkSwitch> - </template> - </div> - </MkSpacer> -</MkModalWindow> -</template> - -<script lang="ts" setup> -import { ref, Ref } from 'vue'; -import MkSwitch from './MkSwitch.vue'; -import MkInfo from './MkInfo.vue'; -import MkButton from './MkButton.vue'; -import MkModalWindow from '@/components/MkModalWindow.vue'; -import { notificationTypes } from '@/const'; -import { i18n } from '@/i18n.js'; - -type TypesMap = Record<typeof notificationTypes[number], Ref<boolean>> - -const emit = defineEmits<{ - (ev: 'done', v: { includingTypes: string[] | null }): void, - (ev: 'closed'): void, -}>(); - -const props = withDefaults(defineProps<{ - includingTypes?: typeof notificationTypes[number][] | null; - showGlobalToggle?: boolean; -}>(), { - includingTypes: () => [], - showGlobalToggle: true, -}); - -let includingTypes = $computed(() => props.includingTypes?.filter(x => notificationTypes.includes(x)) ?? []); - -const dialog = $shallowRef<InstanceType<typeof MkModalWindow>>(); - -const typesMap: TypesMap = notificationTypes.reduce((p, t) => ({ ...p, [t]: ref<boolean>(includingTypes.includes(t)) }), {} as any); -let useGlobalSetting = $ref((includingTypes === null || includingTypes.length === 0) && props.showGlobalToggle); - -function ok() { - if (useGlobalSetting) { - emit('done', { includingTypes: null }); - } else { - emit('done', { - includingTypes: (Object.keys(typesMap) as typeof notificationTypes[number][]) - .filter(type => typesMap[type].value), - }); - } - - if (dialog) dialog.close(); -} - -function disableAll() { - for (const type of notificationTypes) { - typesMap[type].value = false; - } -} - -function enableAll() { - for (const type of notificationTypes) { - typesMap[type].value = true; - } -} -</script> diff --git a/packages/frontend/src/components/MkNotifications.vue b/packages/frontend/src/components/MkNotifications.vue index ad1cb92ce1..6ba2e513c5 100644 --- a/packages/frontend/src/components/MkNotifications.vue +++ b/packages/frontend/src/components/MkNotifications.vue @@ -30,11 +30,11 @@ import MkNote from '@/components/MkNote.vue'; import { useStream } from '@/stream.js'; import { $i } from '@/account.js'; import { i18n } from '@/i18n.js'; -import { notificationTypes } from '@/const'; +import { notificationTypes } from '@/const.js'; import { infoImageUrl } from '@/instance.js'; const props = defineProps<{ - includeTypes?: typeof notificationTypes[number][]; + excludeTypes?: typeof notificationTypes[number][]; }>(); const pagingComponent = shallowRef<InstanceType<typeof MkPagination>>(); @@ -43,13 +43,12 @@ const pagination: Paging = { endpoint: 'i/notifications' as const, limit: 10, params: computed(() => ({ - includeTypes: props.includeTypes ?? undefined, - excludeTypes: props.includeTypes ? undefined : $i.mutingNotificationTypes, + excludeTypes: props.excludeTypes ?? undefined, })), }; const onNotification = (notification) => { - const isMuted = props.includeTypes ? !props.includeTypes.includes(notification.type) : $i.mutingNotificationTypes.includes(notification.type); + const isMuted = props.excludeTypes ? props.excludeTypes.includes(notification.type) : false; if (isMuted || document.visibilityState === 'visible') { useStream().send('readNotification'); } |