2022-11-22 22:40:20 +00:00
|
|
|
<script setup lang="ts">
|
2022-12-03 05:21:53 +00:00
|
|
|
import type { Account, Relationship } from 'masto'
|
2022-11-22 22:40:20 +00:00
|
|
|
|
2022-12-03 05:21:53 +00:00
|
|
|
const { account, command, ...props } = defineProps<{
|
2022-11-22 22:40:20 +00:00
|
|
|
account: Account
|
2022-12-03 05:21:53 +00:00
|
|
|
relationship?: Relationship
|
2022-11-29 08:15:05 +00:00
|
|
|
command?: boolean
|
2022-11-22 22:40:20 +00:00
|
|
|
}>()
|
|
|
|
|
2023-01-03 02:14:54 +00:00
|
|
|
const isSelf = $computed(() => checkUser(currentUser.value) && currentUser.value.account.id === account.id)
|
|
|
|
const enable = $computed(() => !isSelf && !isGuest.value)
|
2022-12-04 16:41:37 +00:00
|
|
|
const relationship = $computed(() => props.relationship || useRelationship(account).value)
|
2022-11-22 22:40:20 +00:00
|
|
|
|
2022-12-25 14:04:50 +00:00
|
|
|
const masto = useMasto()
|
2022-11-22 22:40:20 +00:00
|
|
|
async function toggleFollow() {
|
2022-12-04 16:41:37 +00:00
|
|
|
relationship!.following = !relationship!.following
|
2022-11-26 12:58:10 +00:00
|
|
|
try {
|
2022-12-25 14:04:50 +00:00
|
|
|
const newRel = await masto.accounts[relationship!.following ? 'follow' : 'unfollow'](account.id)
|
2022-12-04 16:41:37 +00:00
|
|
|
Object.assign(relationship!, newRel)
|
2022-11-26 12:58:10 +00:00
|
|
|
}
|
|
|
|
catch {
|
|
|
|
// TODO error handling
|
2022-12-04 16:41:37 +00:00
|
|
|
relationship!.following = !relationship!.following
|
2022-11-26 12:58:10 +00:00
|
|
|
}
|
2022-11-22 22:40:20 +00:00
|
|
|
}
|
2022-11-29 08:15:05 +00:00
|
|
|
|
2022-12-19 14:01:41 +00:00
|
|
|
async function unblock() {
|
|
|
|
relationship!.blocking = false
|
|
|
|
try {
|
2022-12-25 14:04:50 +00:00
|
|
|
const newRel = await masto.accounts.unblock(account.id)
|
2022-12-19 14:01:41 +00:00
|
|
|
Object.assign(relationship!, newRel)
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
// TODO error handling
|
|
|
|
relationship!.blocking = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 14:29:12 +00:00
|
|
|
async function unmute() {
|
|
|
|
relationship!.muting = false
|
|
|
|
try {
|
2022-12-25 14:04:50 +00:00
|
|
|
const newRel = await masto.accounts.unmute(account.id)
|
2022-12-19 14:29:12 +00:00
|
|
|
Object.assign(relationship!, newRel)
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
// TODO error handling
|
|
|
|
relationship!.muting = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-30 02:16:15 +00:00
|
|
|
const { t } = useI18n()
|
|
|
|
|
2022-11-29 08:15:05 +00:00
|
|
|
useCommand({
|
|
|
|
scope: 'Actions',
|
|
|
|
order: -2,
|
|
|
|
visible: () => command && enable,
|
2022-12-04 16:41:37 +00:00
|
|
|
name: () => `${relationship?.following ? t('account.unfollow') : t('account.follow')} ${getShortHandle(account)}`,
|
2022-11-29 08:15:05 +00:00
|
|
|
icon: 'i-ri:star-line',
|
|
|
|
onActivate: () => toggleFollow(),
|
|
|
|
})
|
2022-12-02 21:58:30 +00:00
|
|
|
|
|
|
|
const buttonStyle = $computed(() => {
|
|
|
|
// Skeleton while loading, avoid primary color flash
|
2022-12-04 16:41:37 +00:00
|
|
|
if (!relationship)
|
2022-12-02 21:58:30 +00:00
|
|
|
return 'text-inverted'
|
|
|
|
|
2022-12-19 14:01:41 +00:00
|
|
|
if (relationship.blocking)
|
|
|
|
return 'text-inverted bg-red border-red'
|
|
|
|
|
2022-12-19 14:29:12 +00:00
|
|
|
if (relationship.muting)
|
|
|
|
return 'text-base bg-code border-base'
|
|
|
|
|
2022-12-02 21:58:30 +00:00
|
|
|
// If following, use a label style with a strong border for Mutuals
|
2022-12-04 16:41:37 +00:00
|
|
|
if (relationship.following)
|
|
|
|
return `text-base ${relationship.followedBy ? 'border-strong' : 'border-base'}`
|
2022-12-02 21:58:30 +00:00
|
|
|
|
|
|
|
// If not following, use a button style
|
|
|
|
return 'text-inverted bg-primary border-primary'
|
|
|
|
})
|
2022-11-22 22:40:20 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-23 13:59:13 +00:00
|
|
|
<button
|
2022-11-29 08:15:05 +00:00
|
|
|
v-if="enable"
|
2022-11-29 20:04:23 +00:00
|
|
|
gap-1 items-center group
|
2022-11-28 20:56:24 +00:00
|
|
|
:disabled="relationship?.requested"
|
2022-11-29 20:04:23 +00:00
|
|
|
border-1
|
2022-12-19 14:01:41 +00:00
|
|
|
rounded-full flex="~ gap2 center" font-500 w-30 h-fit py1
|
|
|
|
:class="buttonStyle"
|
2022-12-19 14:29:12 +00:00
|
|
|
:hover="!relationship?.blocking && !relationship?.muting && relationship?.following ? 'border-red text-red' : 'bg-base border-primary text-primary'"
|
|
|
|
@click="relationship?.blocking ? unblock() : relationship?.muting ? unmute() : toggleFollow()"
|
2022-11-23 13:59:13 +00:00
|
|
|
>
|
2022-12-19 14:01:41 +00:00
|
|
|
<template v-if="relationship?.blocking">
|
|
|
|
<span group-hover="hidden">{{ $t('account.blocking') }}</span>
|
|
|
|
<span hidden group-hover="inline">{{ $t('account.unblock') }}</span>
|
|
|
|
</template>
|
2022-12-19 14:29:12 +00:00
|
|
|
<template v-if="relationship?.muting">
|
|
|
|
<span group-hover="hidden">{{ $t('account.muting') }}</span>
|
|
|
|
<span hidden group-hover="inline">{{ $t('account.unmute') }}</span>
|
|
|
|
</template>
|
2022-12-19 14:01:41 +00:00
|
|
|
<template v-else-if="relationship?.following">
|
2022-11-30 02:16:15 +00:00
|
|
|
<span group-hover="hidden">{{ relationship?.followedBy ? $t('account.mutuals') : $t('account.following') }}</span>
|
2022-11-29 20:04:23 +00:00
|
|
|
<span hidden group-hover="inline">{{ $t('account.unfollow') }}</span>
|
|
|
|
</template>
|
|
|
|
<template v-else-if="relationship?.requested">
|
|
|
|
<span>{{ $t('account.follow_requested') }}</span>
|
|
|
|
</template>
|
|
|
|
<template v-else-if="relationship?.followedBy">
|
|
|
|
<span group-hover="hidden">{{ $t('account.follows_you') }}</span>
|
|
|
|
<span hidden group-hover="inline">{{ $t('account.follow_back') }}</span>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<span>{{ $t('account.follow') }}</span>
|
|
|
|
</template>
|
2022-11-22 22:40:20 +00:00
|
|
|
</button>
|
|
|
|
</template>
|