forked from Mirrors/elk
feat: allow to set mute duration and notifications mute option (#2665)
This commit is contained in:
parent
4954473f50
commit
3448335356
10 changed files with 163 additions and 47 deletions
|
@ -25,13 +25,16 @@ function shareAccount() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function toggleReblogs() {
|
async function toggleReblogs() {
|
||||||
if (!relationship.value!.showingReblogs && await openConfirmDialog({
|
if (!relationship.value!.showingReblogs) {
|
||||||
title: t('confirm.show_reblogs.title'),
|
const dialogChoice = await openConfirmDialog({
|
||||||
description: t('confirm.show_reblogs.description', [account.acct]),
|
title: t('confirm.show_reblogs.title'),
|
||||||
confirm: t('confirm.show_reblogs.confirm'),
|
description: t('confirm.show_reblogs.description', [account.acct]),
|
||||||
cancel: t('confirm.show_reblogs.cancel'),
|
confirm: t('confirm.show_reblogs.confirm'),
|
||||||
}) !== 'confirm')
|
cancel: t('confirm.show_reblogs.cancel'),
|
||||||
return
|
})
|
||||||
|
if (dialogChoice.choice !== 'confirm')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const showingReblogs = !relationship.value?.showingReblogs
|
const showingReblogs = !relationship.value?.showingReblogs
|
||||||
relationship.value = await client.value.v1.accounts.$select(account.id).follow({ reblogs: showingReblogs })
|
relationship.value = await client.value.v1.accounts.$select(account.id).follow({ reblogs: showingReblogs })
|
||||||
|
|
|
@ -4,6 +4,8 @@ defineProps<{
|
||||||
hover?: boolean
|
hover?: boolean
|
||||||
iconChecked?: string
|
iconChecked?: string
|
||||||
iconUnchecked?: string
|
iconUnchecked?: string
|
||||||
|
checkedIconColor?: string
|
||||||
|
prependCheckbox?: boolean
|
||||||
}>()
|
}>()
|
||||||
const modelValue = defineModel<boolean | null>()
|
const modelValue = defineModel<boolean | null>()
|
||||||
</script>
|
</script>
|
||||||
|
@ -15,9 +17,12 @@ const modelValue = defineModel<boolean | null>()
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
@click.prevent="modelValue = !modelValue"
|
@click.prevent="modelValue = !modelValue"
|
||||||
>
|
>
|
||||||
<span v-if="label" flex-1 ms-2 pointer-events-none>{{ label }}</span>
|
<span v-if="label && !prependCheckbox" flex-1 ms-2 pointer-events-none>{{ label }}</span>
|
||||||
<span
|
<span
|
||||||
:class="modelValue ? (iconChecked ?? 'i-ri:checkbox-line') : (iconUnchecked ?? 'i-ri:checkbox-blank-line')"
|
:class="[
|
||||||
|
modelValue ? (iconChecked ?? 'i-ri:checkbox-line') : (iconUnchecked ?? 'i-ri:checkbox-blank-line'),
|
||||||
|
modelValue && checkedIconColor,
|
||||||
|
]"
|
||||||
text-lg
|
text-lg
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
/>
|
/>
|
||||||
|
@ -26,6 +31,7 @@ const modelValue = defineModel<boolean | null>()
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
sr-only
|
sr-only
|
||||||
>
|
>
|
||||||
|
<span v-if="label && prependCheckbox" flex-1 ms-2 pointer-events-none>{{ label }}</span>
|
||||||
</label>
|
</label>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ async function removeList() {
|
||||||
actionError.value = undefined
|
actionError.value = undefined
|
||||||
await nextTick()
|
await nextTick()
|
||||||
|
|
||||||
if (confirmDelete === 'confirm') {
|
if (confirmDelete.choice === 'confirm') {
|
||||||
await nextTick()
|
await nextTick()
|
||||||
try {
|
try {
|
||||||
await client.v1.lists.$select(list.value.id).remove()
|
await client.v1.lists.$select(list.value.id).remove()
|
||||||
|
|
45
components/modal/DurationPicker.vue
Normal file
45
components/modal/DurationPicker.vue
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
const model = defineModel<number>()
|
||||||
|
const isValid = defineModel<boolean>('isValid')
|
||||||
|
|
||||||
|
const days = ref<number | ''>(0)
|
||||||
|
const hours = ref<number | ''>(1)
|
||||||
|
const minutes = ref<number | ''>(0)
|
||||||
|
|
||||||
|
watchEffect(() => {
|
||||||
|
if (days.value === '' || hours.value === '' || minutes.value === '') {
|
||||||
|
isValid.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const duration
|
||||||
|
= days.value * 24 * 60 * 60
|
||||||
|
+ hours.value * 60 * 60
|
||||||
|
+ minutes.value * 60
|
||||||
|
|
||||||
|
if (duration <= 0) {
|
||||||
|
isValid.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isValid.value = true
|
||||||
|
model.value = duration
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div flex flex-grow-0 gap-2>
|
||||||
|
<label flex items-center gap-2>
|
||||||
|
<input v-model="days" type="number" min="0" max="1999" input-base :class="!isValid ? 'input-error' : null">
|
||||||
|
{{ $t('confirm.mute_account.days', days === '' ? 0 : days) }}
|
||||||
|
</label>
|
||||||
|
<label flex items-center gap-2>
|
||||||
|
<input v-model="hours" type="number" min="0" max="24" input-base :class="!isValid ? 'input-error' : null">
|
||||||
|
{{ $t('confirm.mute_account.hours', hours === '' ? 0 : hours) }}
|
||||||
|
</label>
|
||||||
|
<label flex items-center gap-2>
|
||||||
|
<input v-model="minutes" type="number" min="0" max="59" step="5" input-base :class="!isValid ? 'input-error' : null">
|
||||||
|
{{ $t('confirm.mute_account.minute', minutes === '' ? 0 : minutes) }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</template>
|
|
@ -1,11 +1,34 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { ConfirmDialogChoice, ConfirmDialogLabel } from '~/types'
|
import type { ConfirmDialogChoice, ConfirmDialogOptions } from '~/types'
|
||||||
|
import DurationPicker from '~/components/modal/DurationPicker.vue'
|
||||||
|
|
||||||
defineProps<ConfirmDialogLabel>()
|
const props = defineProps<ConfirmDialogOptions>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(evt: 'choice', choice: ConfirmDialogChoice): void
|
(evt: 'choice', choice: ConfirmDialogChoice): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
const hasDuration = ref(false)
|
||||||
|
const isValidDuration = ref(true)
|
||||||
|
const duration = ref(60 * 60) // default to 1 hour
|
||||||
|
const shouldMuteNotifications = ref(true)
|
||||||
|
const isMute = computed(() => props.extraOptionType === 'mute')
|
||||||
|
|
||||||
|
function handleChoice(choice: ConfirmDialogChoice['choice']) {
|
||||||
|
const dialogChoice = {
|
||||||
|
choice,
|
||||||
|
...isMute && {
|
||||||
|
extraOptions: {
|
||||||
|
mute: {
|
||||||
|
duration: hasDuration.value ? duration.value : 0,
|
||||||
|
notifications: shouldMuteNotifications.value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
emit('choice', dialogChoice)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -16,11 +39,17 @@ const emit = defineEmits<{
|
||||||
<div v-if="description">
|
<div v-if="description">
|
||||||
{{ description }}
|
{{ description }}
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="isMute" flex-col flex gap-4>
|
||||||
|
<CommonCheckbox v-model="hasDuration" :label="$t('confirm.mute_account.specify_duration')" prepend-checkbox checked-icon-color="text-primary" />
|
||||||
|
<DurationPicker v-if="hasDuration" v-model="duration" v-model:is-valid="isValidDuration" />
|
||||||
|
<CommonCheckbox v-model="shouldMuteNotifications" :label="$t('confirm.mute_account.notifications')" prepend-checkbox checked-icon-color="text-primary" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div flex justify-end gap-2>
|
<div flex justify-end gap-2>
|
||||||
<button btn-text @click="emit('choice', 'cancel')">
|
<button btn-text @click="handleChoice('cancel')">
|
||||||
{{ cancel || $t('confirm.common.cancel') }}
|
{{ cancel || $t('confirm.common.cancel') }}
|
||||||
</button>
|
</button>
|
||||||
<button btn-solid @click="emit('choice', 'confirm')">
|
<button btn-solid :disabled="!isValidDuration" @click="handleChoice('confirm')">
|
||||||
{{ confirm || $t('confirm.common.confirm') }}
|
{{ confirm || $t('confirm.common.confirm') }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -62,12 +62,13 @@ async function shareLink(status: mastodon.v1.Status) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteStatus() {
|
async function deleteStatus() {
|
||||||
if (await openConfirmDialog({
|
const confirmDelete = await openConfirmDialog({
|
||||||
title: t('confirm.delete_posts.title'),
|
title: t('confirm.delete_posts.title'),
|
||||||
description: t('confirm.delete_posts.description'),
|
description: t('confirm.delete_posts.description'),
|
||||||
confirm: t('confirm.delete_posts.confirm'),
|
confirm: t('confirm.delete_posts.confirm'),
|
||||||
cancel: t('confirm.delete_posts.cancel'),
|
cancel: t('confirm.delete_posts.cancel'),
|
||||||
}) !== 'confirm')
|
})
|
||||||
|
if (confirmDelete.choice !== 'confirm')
|
||||||
return
|
return
|
||||||
|
|
||||||
removeCachedStatus(status.value.id)
|
removeCachedStatus(status.value.id)
|
||||||
|
@ -80,12 +81,13 @@ async function deleteStatus() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteAndRedraft() {
|
async function deleteAndRedraft() {
|
||||||
if (await openConfirmDialog({
|
const confirmDelete = await openConfirmDialog({
|
||||||
title: t('confirm.delete_posts.title'),
|
title: t('confirm.delete_posts.title'),
|
||||||
description: t('confirm.delete_posts.description'),
|
description: t('confirm.delete_posts.description'),
|
||||||
confirm: t('confirm.delete_posts.confirm'),
|
confirm: t('confirm.delete_posts.confirm'),
|
||||||
cancel: t('confirm.delete_posts.cancel'),
|
cancel: t('confirm.delete_posts.cancel'),
|
||||||
}) !== 'confirm')
|
})
|
||||||
|
if (confirmDelete.choice !== 'confirm')
|
||||||
return
|
return
|
||||||
|
|
||||||
if (import.meta.dev) {
|
if (import.meta.dev) {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import type { mastodon } from 'masto'
|
import type { mastodon } from 'masto'
|
||||||
import type { ConfirmDialogChoice, ConfirmDialogLabel, Draft, ErrorDialogData } from '~/types'
|
import type { ConfirmDialogChoice, ConfirmDialogOptions, Draft, ErrorDialogData } from '~/types'
|
||||||
import { STORAGE_KEY_FIRST_VISIT } from '~/constants'
|
import { STORAGE_KEY_FIRST_VISIT } from '~/constants'
|
||||||
|
|
||||||
export const confirmDialogChoice = ref<ConfirmDialogChoice>()
|
export const confirmDialogChoice = ref<ConfirmDialogChoice>()
|
||||||
export const confirmDialogLabel = ref<ConfirmDialogLabel>()
|
export const confirmDialogLabel = ref<ConfirmDialogOptions>()
|
||||||
export const errorDialogData = ref<ErrorDialogData>()
|
export const errorDialogData = ref<ErrorDialogData>()
|
||||||
|
|
||||||
export const mediaPreviewList = ref<mastodon.v1.MediaAttachment[]>([])
|
export const mediaPreviewList = ref<mastodon.v1.MediaAttachment[]>([])
|
||||||
|
@ -39,7 +39,7 @@ export function openSigninDialog() {
|
||||||
isSigninDialogOpen.value = true
|
isSigninDialogOpen.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function openConfirmDialog(label: ConfirmDialogLabel | string): Promise<ConfirmDialogChoice> {
|
export async function openConfirmDialog(label: ConfirmDialogOptions | string): Promise<ConfirmDialogChoice> {
|
||||||
confirmDialogLabel.value = typeof label === 'string' ? { title: label } : label
|
confirmDialogLabel.value = typeof label === 'string' ? { title: label } : label
|
||||||
confirmDialogChoice.value = undefined
|
confirmDialogChoice.value = undefined
|
||||||
isConfirmDialogOpen.value = true
|
isConfirmDialogOpen.value = true
|
||||||
|
|
|
@ -39,12 +39,13 @@ export async function toggleFollowAccount(relationship: mastodon.v1.Relationship
|
||||||
const unfollow = relationship!.following || relationship!.requested
|
const unfollow = relationship!.following || relationship!.requested
|
||||||
|
|
||||||
if (unfollow) {
|
if (unfollow) {
|
||||||
if (await openConfirmDialog({
|
const confirmUnfollow = await openConfirmDialog({
|
||||||
title: i18n.t('confirm.unfollow.title'),
|
title: i18n.t('confirm.unfollow.title'),
|
||||||
description: i18n.t('confirm.unfollow.description', [`@${account.acct}`]),
|
description: i18n.t('confirm.unfollow.description', [`@${account.acct}`]),
|
||||||
confirm: i18n.t('confirm.unfollow.confirm'),
|
confirm: i18n.t('confirm.unfollow.confirm'),
|
||||||
cancel: i18n.t('confirm.unfollow.cancel'),
|
cancel: i18n.t('confirm.unfollow.cancel'),
|
||||||
}) !== 'confirm')
|
})
|
||||||
|
if (confirmUnfollow.choice !== 'confirm')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,18 +67,28 @@ export async function toggleMuteAccount(relationship: mastodon.v1.Relationship,
|
||||||
const { client } = useMasto()
|
const { client } = useMasto()
|
||||||
const i18n = useNuxtApp().$i18n
|
const i18n = useNuxtApp().$i18n
|
||||||
|
|
||||||
if (!relationship!.muting && await openConfirmDialog({
|
let duration = 0 // default 0 == indefinite
|
||||||
title: i18n.t('confirm.mute_account.title'),
|
let notifications = true // default true = mute notifications
|
||||||
description: i18n.t('confirm.mute_account.description', [account.acct]),
|
if (!relationship!.muting) {
|
||||||
confirm: i18n.t('confirm.mute_account.confirm'),
|
const confirmMute = await openConfirmDialog({
|
||||||
cancel: i18n.t('confirm.mute_account.cancel'),
|
title: i18n.t('confirm.mute_account.title'),
|
||||||
}) !== 'confirm')
|
description: i18n.t('confirm.mute_account.description', [account.acct]),
|
||||||
return
|
confirm: i18n.t('confirm.mute_account.confirm'),
|
||||||
|
cancel: i18n.t('confirm.mute_account.cancel'),
|
||||||
|
extraOptionType: 'mute',
|
||||||
|
})
|
||||||
|
if (confirmMute.choice !== 'confirm')
|
||||||
|
return
|
||||||
|
|
||||||
|
duration = confirmMute.extraOptions!.mute.duration
|
||||||
|
notifications = confirmMute.extraOptions!.mute.notifications
|
||||||
|
}
|
||||||
|
|
||||||
relationship!.muting = !relationship!.muting
|
relationship!.muting = !relationship!.muting
|
||||||
relationship = relationship!.muting
|
relationship = relationship!.muting
|
||||||
? await client.value.v1.accounts.$select(account.id).mute({
|
? await client.value.v1.accounts.$select(account.id).mute({
|
||||||
// TODO support more options
|
duration,
|
||||||
|
notifications,
|
||||||
})
|
})
|
||||||
: await client.value.v1.accounts.$select(account.id).unmute()
|
: await client.value.v1.accounts.$select(account.id).unmute()
|
||||||
}
|
}
|
||||||
|
@ -86,13 +97,16 @@ export async function toggleBlockAccount(relationship: mastodon.v1.Relationship,
|
||||||
const { client } = useMasto()
|
const { client } = useMasto()
|
||||||
const i18n = useNuxtApp().$i18n
|
const i18n = useNuxtApp().$i18n
|
||||||
|
|
||||||
if (!relationship!.blocking && await openConfirmDialog({
|
if (!relationship!.blocking) {
|
||||||
title: i18n.t('confirm.block_account.title'),
|
const confirmBlock = await openConfirmDialog({
|
||||||
description: i18n.t('confirm.block_account.description', [account.acct]),
|
title: i18n.t('confirm.block_account.title'),
|
||||||
confirm: i18n.t('confirm.block_account.confirm'),
|
description: i18n.t('confirm.block_account.description', [account.acct]),
|
||||||
cancel: i18n.t('confirm.block_account.cancel'),
|
confirm: i18n.t('confirm.block_account.confirm'),
|
||||||
}) !== 'confirm')
|
cancel: i18n.t('confirm.block_account.cancel'),
|
||||||
return
|
})
|
||||||
|
if (confirmBlock.choice !== 'confirm')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
relationship!.blocking = !relationship!.blocking
|
relationship!.blocking = !relationship!.blocking
|
||||||
relationship = await client.value.v1.accounts.$select(account.id)[relationship!.blocking ? 'block' : 'unblock']()
|
relationship = await client.value.v1.accounts.$select(account.id)[relationship!.blocking ? 'block' : 'unblock']()
|
||||||
|
@ -102,13 +116,16 @@ export async function toggleBlockDomain(relationship: mastodon.v1.Relationship,
|
||||||
const { client } = useMasto()
|
const { client } = useMasto()
|
||||||
const i18n = useNuxtApp().$i18n
|
const i18n = useNuxtApp().$i18n
|
||||||
|
|
||||||
if (!relationship!.domainBlocking && await openConfirmDialog({
|
if (!relationship!.domainBlocking) {
|
||||||
title: i18n.t('confirm.block_domain.title'),
|
const confirmDomainBlock = await openConfirmDialog({
|
||||||
description: i18n.t('confirm.block_domain.description', [getServerName(account)]),
|
title: i18n.t('confirm.block_domain.title'),
|
||||||
confirm: i18n.t('confirm.block_domain.confirm'),
|
description: i18n.t('confirm.block_domain.description', [getServerName(account)]),
|
||||||
cancel: i18n.t('confirm.block_domain.cancel'),
|
confirm: i18n.t('confirm.block_domain.confirm'),
|
||||||
}) !== 'confirm')
|
cancel: i18n.t('confirm.block_domain.cancel'),
|
||||||
return
|
})
|
||||||
|
if (confirmDomainBlock.choice !== 'confirm')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
relationship!.domainBlocking = !relationship!.domainBlocking
|
relationship!.domainBlocking = !relationship!.domainBlocking
|
||||||
await client.value.v1.domainBlocks[relationship!.domainBlocking ? 'create' : 'remove']({ domain: getServerName(account) })
|
await client.value.v1.domainBlocks[relationship!.domainBlocking ? 'create' : 'remove']({ domain: getServerName(account) })
|
||||||
|
|
|
@ -149,7 +149,12 @@
|
||||||
"mute_account": {
|
"mute_account": {
|
||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
"confirm": "Mute",
|
"confirm": "Mute",
|
||||||
|
"days": "days|day|days",
|
||||||
"description": "Are you sure you want to mute {0}?",
|
"description": "Are you sure you want to mute {0}?",
|
||||||
|
"hours": "hours|hour|hours",
|
||||||
|
"minute": "minutes|minute|minutes",
|
||||||
|
"notifications": "Mute notifications",
|
||||||
|
"specify_duration": "Specify mute duration",
|
||||||
"title": "Mute account"
|
"title": "Mute account"
|
||||||
},
|
},
|
||||||
"show_reblogs": {
|
"show_reblogs": {
|
||||||
|
|
|
@ -56,13 +56,22 @@ export interface Draft {
|
||||||
|
|
||||||
export type DraftMap = Record<string, Draft>
|
export type DraftMap = Record<string, Draft>
|
||||||
|
|
||||||
export interface ConfirmDialogLabel {
|
export interface ConfirmDialogOptions {
|
||||||
title: string
|
title: string
|
||||||
description?: string
|
description?: string
|
||||||
confirm?: string
|
confirm?: string
|
||||||
cancel?: string
|
cancel?: string
|
||||||
|
extraOptionType?: 'mute'
|
||||||
|
}
|
||||||
|
export interface ConfirmDialogChoice {
|
||||||
|
choice: 'confirm' | 'cancel'
|
||||||
|
extraOptions?: {
|
||||||
|
mute: {
|
||||||
|
duration: number
|
||||||
|
notifications: boolean
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export type ConfirmDialogChoice = 'confirm' | 'cancel'
|
|
||||||
|
|
||||||
export interface CommonRouteTabOption {
|
export interface CommonRouteTabOption {
|
||||||
to: RouteLocationRaw
|
to: RouteLocationRaw
|
||||||
|
|
Loading…
Reference in a new issue