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