mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-07 01:19:57 +00:00
feat(account): predict relationship from context
This commit is contained in:
parent
b4cda4338f
commit
88731ee18d
6 changed files with 20 additions and 10 deletions
|
@ -4,6 +4,7 @@ import type { mastodon } from 'masto'
|
||||||
const { account } = defineProps<{
|
const { account } = defineProps<{
|
||||||
account: mastodon.v1.Account
|
account: mastodon.v1.Account
|
||||||
hoverCard?: boolean
|
hoverCard?: boolean
|
||||||
|
relationshipContext?: 'followedBy' | 'following'
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
cacheAccount(account)
|
cacheAccount(account)
|
||||||
|
@ -19,7 +20,7 @@ cacheAccount(account)
|
||||||
:to="getAccountRoute(account)"
|
:to="getAccountRoute(account)"
|
||||||
/>
|
/>
|
||||||
<div h-full p1 shrink-0>
|
<div h-full p1 shrink-0>
|
||||||
<AccountFollowButton :account="account" />
|
<AccountFollowButton :account="account" :context="relationshipContext" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { mastodon } from 'masto'
|
import type { mastodon } from 'masto'
|
||||||
|
|
||||||
const { account, command, ...props } = defineProps<{
|
const { account, command, context, ...props } = defineProps<{
|
||||||
account: mastodon.v1.Account
|
account: mastodon.v1.Account
|
||||||
relationship?: mastodon.v1.Relationship
|
relationship?: mastodon.v1.Relationship
|
||||||
|
context?: 'followedBy' | 'following'
|
||||||
command?: boolean
|
command?: boolean
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
@ -67,8 +68,8 @@ const buttonStyle = $computed(() => {
|
||||||
return 'text-base bg-code border-base'
|
return 'text-base bg-code border-base'
|
||||||
|
|
||||||
// If following, use a label style with a strong border for Mutuals
|
// If following, use a label style with a strong border for Mutuals
|
||||||
if (relationship?.following)
|
if (relationship ? relationship.following : context === 'following')
|
||||||
return `text-base ${relationship.followedBy ? 'border-strong' : 'border-base'}`
|
return `text-base ${relationship?.followedBy ? 'border-strong' : 'border-base'}`
|
||||||
|
|
||||||
// If not following, use a button style
|
// If not following, use a button style
|
||||||
return 'text-inverted bg-primary border-primary'
|
return 'text-inverted bg-primary border-primary'
|
||||||
|
@ -94,14 +95,14 @@ const buttonStyle = $computed(() => {
|
||||||
<span group-hover="hidden">{{ $t('account.muting') }}</span>
|
<span group-hover="hidden">{{ $t('account.muting') }}</span>
|
||||||
<span hidden group-hover="inline">{{ $t('account.unmute') }}</span>
|
<span hidden group-hover="inline">{{ $t('account.unmute') }}</span>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="relationship?.following">
|
<template v-else-if="relationship ? relationship.following : context === 'following'">
|
||||||
<span group-hover="hidden">{{ relationship.followedBy ? $t('account.mutuals') : $t('account.following') }}</span>
|
<span group-hover="hidden">{{ relationship?.followedBy ? $t('account.mutuals') : $t('account.following') }}</span>
|
||||||
<span hidden group-hover="inline">{{ $t('account.unfollow') }}</span>
|
<span hidden group-hover="inline">{{ $t('account.unfollow') }}</span>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="relationship?.requested">
|
<template v-else-if="relationship?.requested">
|
||||||
<span>{{ $t('account.follow_requested') }}</span>
|
<span>{{ $t('account.follow_requested') }}</span>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="relationship?.followedBy">
|
<template v-else-if="relationship ? relationship.followedBy : context === 'followedBy'">
|
||||||
<span group-hover="hidden">{{ $t('account.follows_you') }}</span>
|
<span group-hover="hidden">{{ $t('account.follows_you') }}</span>
|
||||||
<span hidden group-hover="inline">{{ $t('account.follow_back') }}</span>
|
<span hidden group-hover="inline">{{ $t('account.follow_back') }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import type { Paginator, mastodon } from 'masto'
|
||||||
|
|
||||||
const { paginator } = defineProps<{
|
const { paginator } = defineProps<{
|
||||||
paginator: Paginator<mastodon.v1.Account[], mastodon.DefaultPaginationParams>
|
paginator: Paginator<mastodon.v1.Account[], mastodon.DefaultPaginationParams>
|
||||||
|
relationshipContext?: 'followedBy' | 'following'
|
||||||
}>()
|
}>()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -11,6 +12,7 @@ const { paginator } = defineProps<{
|
||||||
<template #default="{ item }">
|
<template #default="{ item }">
|
||||||
<AccountCard
|
<AccountCard
|
||||||
:account="item"
|
:account="item"
|
||||||
|
:relationship-context="relationshipContext"
|
||||||
hover-card
|
hover-card
|
||||||
border="b base" py2 px4
|
border="b base" py2 px4
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { login as loginMasto } from 'masto'
|
import { login as loginMasto } from 'masto'
|
||||||
import type { WsEvents, mastodon } from 'masto'
|
import type { WsEvents, mastodon } from 'masto'
|
||||||
import type { Ref } from 'vue'
|
import type { Ref } from 'vue'
|
||||||
import type { RemovableRef } from '@vueuse/core'
|
import type { MaybeComputedRef, RemovableRef } from '@vueuse/core'
|
||||||
import type { ElkMasto, UserLogin } from '~/types'
|
import type { ElkMasto, UserLogin } from '~/types'
|
||||||
import {
|
import {
|
||||||
DEFAULT_POST_CHARS_LIMIT,
|
DEFAULT_POST_CHARS_LIMIT,
|
||||||
|
@ -96,6 +96,8 @@ export const currentUserHandle = computed(() => currentUser.value?.account.id
|
||||||
)
|
)
|
||||||
|
|
||||||
export const useUsers = () => users
|
export const useUsers = () => users
|
||||||
|
export const useSelfAccount = (user: MaybeComputedRef<mastodon.v1.Account | undefined>) =>
|
||||||
|
computed(() => currentUser.value && resolveUnref(user)?.id === currentUser.value.account.id)
|
||||||
|
|
||||||
export const characterLimit = computed(() => currentInstance.value?.configuration.statuses.maxCharacters ?? DEFAULT_POST_CHARS_LIMIT)
|
export const characterLimit = computed(() => currentInstance.value?.configuration.statuses.maxCharacters ?? DEFAULT_POST_CHARS_LIMIT)
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ definePageMeta({ name: 'account-followers' })
|
||||||
const account = await fetchAccountByHandle(handle)
|
const account = await fetchAccountByHandle(handle)
|
||||||
const paginator = account ? useMasto().v1.accounts.listFollowers(account.id, {}) : null
|
const paginator = account ? useMasto().v1.accounts.listFollowers(account.id, {}) : null
|
||||||
|
|
||||||
|
const isSelf = useSelfAccount(account)
|
||||||
|
|
||||||
if (account) {
|
if (account) {
|
||||||
useHeadFixed({
|
useHeadFixed({
|
||||||
title: () => `${t('account.followers')} | ${getDisplayName(account)} (@${account})`,
|
title: () => `${t('account.followers')} | ${getDisplayName(account)} (@${account})`,
|
||||||
|
@ -17,6 +19,6 @@ if (account) {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<template v-if="paginator">
|
<template v-if="paginator">
|
||||||
<AccountPaginator :paginator="paginator" />
|
<AccountPaginator :paginator="paginator" :relationship-context="isSelf ? 'followedBy' : undefined" />
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -8,6 +8,8 @@ definePageMeta({ name: 'account-following' })
|
||||||
const account = await fetchAccountByHandle(handle)
|
const account = await fetchAccountByHandle(handle)
|
||||||
const paginator = account ? useMasto().v1.accounts.listFollowing(account.id, {}) : null
|
const paginator = account ? useMasto().v1.accounts.listFollowing(account.id, {}) : null
|
||||||
|
|
||||||
|
const isSelf = useSelfAccount(account)
|
||||||
|
|
||||||
if (account) {
|
if (account) {
|
||||||
useHeadFixed({
|
useHeadFixed({
|
||||||
title: () => `${t('account.following')} | ${getDisplayName(account)} (@${account.acct})`,
|
title: () => `${t('account.following')} | ${getDisplayName(account)} (@${account.acct})`,
|
||||||
|
@ -17,6 +19,6 @@ if (account) {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<template v-if="paginator">
|
<template v-if="paginator">
|
||||||
<AccountPaginator :paginator="paginator" />
|
<AccountPaginator :paginator="paginator" :relationship-context="isSelf ? 'following' : undefined" />
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in a new issue