2022-11-23 07:40:20 +09:00
|
|
|
<script setup lang="ts">
|
2023-01-08 15:21:09 +09:00
|
|
|
import type { mastodon } from 'masto'
|
2023-06-23 21:24:10 +09:00
|
|
|
import { toggleFollowAccount, useRelationship } from '~~/composables/masto/relationship'
|
2022-11-23 07:40:20 +09:00
|
|
|
|
2023-01-10 16:49:49 +09:00
|
|
|
const { account, command, context, ...props } = defineProps<{
|
2023-01-08 15:21:09 +09:00
|
|
|
account: mastodon.v1.Account
|
|
|
|
relationship?: mastodon.v1.Relationship
|
2023-01-10 16:49:49 +09:00
|
|
|
context?: 'followedBy' | 'following'
|
2022-11-29 17:15:05 +09:00
|
|
|
command?: boolean
|
2022-11-23 07:40:20 +09:00
|
|
|
}>()
|
|
|
|
|
2023-01-16 15:36:28 +09:00
|
|
|
const { t } = useI18n()
|
2023-01-14 22:04:44 +09:00
|
|
|
const isSelf = $(useSelfAccount(() => account))
|
2022-11-29 17:15:05 +09:00
|
|
|
const enable = $computed(() => !isSelf && currentUser.value)
|
2022-12-05 01:41:37 +09:00
|
|
|
const relationship = $computed(() => props.relationship || useRelationship(account).value)
|
2022-11-23 07:40:20 +09:00
|
|
|
|
2023-01-15 17:38:02 +09:00
|
|
|
const { client } = $(useMasto())
|
2022-11-29 17:15:05 +09:00
|
|
|
|
2022-12-19 23:01:41 +09:00
|
|
|
async function unblock() {
|
|
|
|
relationship!.blocking = false
|
|
|
|
try {
|
2023-01-15 17:38:02 +09:00
|
|
|
const newRel = await client.v1.accounts.unblock(account.id)
|
2022-12-19 23:01:41 +09:00
|
|
|
Object.assign(relationship!, newRel)
|
|
|
|
}
|
2023-01-12 14:39:22 +09:00
|
|
|
catch (err) {
|
|
|
|
console.error(err)
|
2022-12-19 23:01:41 +09:00
|
|
|
// TODO error handling
|
|
|
|
relationship!.blocking = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 23:29:12 +09:00
|
|
|
async function unmute() {
|
|
|
|
relationship!.muting = false
|
|
|
|
try {
|
2023-01-15 17:38:02 +09:00
|
|
|
const newRel = await client.v1.accounts.unmute(account.id)
|
2022-12-19 23:29:12 +09:00
|
|
|
Object.assign(relationship!, newRel)
|
|
|
|
}
|
2023-01-12 14:39:22 +09:00
|
|
|
catch (err) {
|
|
|
|
console.error(err)
|
2022-12-19 23:29:12 +09:00
|
|
|
// TODO error handling
|
|
|
|
relationship!.muting = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-29 17:15:05 +09:00
|
|
|
useCommand({
|
|
|
|
scope: 'Actions',
|
|
|
|
order: -2,
|
|
|
|
visible: () => command && enable,
|
2022-12-05 01:41:37 +09:00
|
|
|
name: () => `${relationship?.following ? t('account.unfollow') : t('account.follow')} ${getShortHandle(account)}`,
|
2022-11-29 17:15:05 +09:00
|
|
|
icon: 'i-ri:star-line',
|
2023-06-23 21:24:10 +09:00
|
|
|
onActivate: () => toggleFollowAccount(relationship!, account),
|
2022-11-29 17:15:05 +09:00
|
|
|
})
|
2022-12-03 06:58:30 +09:00
|
|
|
|
|
|
|
const buttonStyle = $computed(() => {
|
2023-01-09 17:46:28 +09:00
|
|
|
if (relationship?.blocking)
|
2022-12-19 23:01:41 +09:00
|
|
|
return 'text-inverted bg-red border-red'
|
|
|
|
|
2023-01-09 17:46:28 +09:00
|
|
|
if (relationship?.muting)
|
2023-01-10 18:05:59 +09:00
|
|
|
return 'text-base bg-card border-base'
|
2022-12-19 23:29:12 +09:00
|
|
|
|
2022-12-03 06:58:30 +09:00
|
|
|
// If following, use a label style with a strong border for Mutuals
|
2023-01-10 16:49:49 +09:00
|
|
|
if (relationship ? relationship.following : context === 'following')
|
|
|
|
return `text-base ${relationship?.followedBy ? 'border-strong' : 'border-base'}`
|
2022-12-03 06:58:30 +09:00
|
|
|
|
|
|
|
// If not following, use a button style
|
|
|
|
return 'text-inverted bg-primary border-primary'
|
|
|
|
})
|
2022-11-23 07:40:20 +09:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-23 22:59:13 +09:00
|
|
|
<button
|
2022-11-29 17:15:05 +09:00
|
|
|
v-if="enable"
|
2022-11-30 05:04:23 +09:00
|
|
|
gap-1 items-center group
|
2022-11-29 05:56:24 +09:00
|
|
|
:disabled="relationship?.requested"
|
2022-11-30 05:04:23 +09:00
|
|
|
border-1
|
2023-01-09 04:35:48 +09:00
|
|
|
rounded-full flex="~ gap2 center" font-500 min-w-30 h-fit px3 py1
|
2022-12-19 23:01:41 +09:00
|
|
|
:class="buttonStyle"
|
2022-12-19 23:29:12 +09:00
|
|
|
:hover="!relationship?.blocking && !relationship?.muting && relationship?.following ? 'border-red text-red' : 'bg-base border-primary text-primary'"
|
2023-06-23 21:24:10 +09:00
|
|
|
@click="relationship?.blocking ? unblock() : relationship?.muting ? unmute() : toggleFollowAccount(relationship!, account)"
|
2022-11-23 22:59:13 +09:00
|
|
|
>
|
2022-12-19 23:01:41 +09:00
|
|
|
<template v-if="relationship?.blocking">
|
2023-03-19 21:24:27 +09:00
|
|
|
<span elk-group-hover="hidden">{{ $t('account.blocking') }}</span>
|
|
|
|
<span hidden elk-group-hover="inline">{{ $t('account.unblock') }}</span>
|
2022-12-19 23:01:41 +09:00
|
|
|
</template>
|
2022-12-19 23:29:12 +09:00
|
|
|
<template v-if="relationship?.muting">
|
2023-03-19 21:24:27 +09:00
|
|
|
<span elk-group-hover="hidden">{{ $t('account.muting') }}</span>
|
|
|
|
<span hidden elk-group-hover="inline">{{ $t('account.unmute') }}</span>
|
2022-12-19 23:29:12 +09:00
|
|
|
</template>
|
2023-01-10 16:49:49 +09:00
|
|
|
<template v-else-if="relationship ? relationship.following : context === 'following'">
|
2023-03-19 21:24:27 +09:00
|
|
|
<span elk-group-hover="hidden">{{ relationship?.followedBy ? $t('account.mutuals') : $t('account.following') }}</span>
|
|
|
|
<span hidden elk-group-hover="inline">{{ $t('account.unfollow') }}</span>
|
2022-11-30 05:04:23 +09:00
|
|
|
</template>
|
|
|
|
<template v-else-if="relationship?.requested">
|
|
|
|
<span>{{ $t('account.follow_requested') }}</span>
|
|
|
|
</template>
|
2023-01-10 16:49:49 +09:00
|
|
|
<template v-else-if="relationship ? relationship.followedBy : context === 'followedBy'">
|
2023-03-19 21:24:27 +09:00
|
|
|
<span elk-group-hover="hidden">{{ $t('account.follows_you') }}</span>
|
|
|
|
<span hidden elk-group-hover="inline">{{ $t('account.follow_back') }}</span>
|
2022-11-30 05:04:23 +09:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
2023-02-05 06:26:37 +09:00
|
|
|
<span>{{ account.locked ? $t('account.request_follow') : $t('account.follow') }}</span>
|
2022-11-30 05:04:23 +09:00
|
|
|
</template>
|
2022-11-23 07:40:20 +09:00
|
|
|
</button>
|
|
|
|
</template>
|