2021-01-20 18:16:44 +01:00
|
|
|
<template>
|
|
|
|
<div>
|
2022-01-10 15:19:16 +01:00
|
|
|
<breadcrumbs-nav
|
|
|
|
v-if="group"
|
|
|
|
:links="[
|
|
|
|
{
|
|
|
|
name: RouteName.GROUP,
|
|
|
|
params: { preferredUsername: usernameWithDomain(group) },
|
|
|
|
text: displayName(group),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: RouteName.GROUP_SETTINGS,
|
|
|
|
params: { preferredUsername: usernameWithDomain(group) },
|
|
|
|
text: $t('Settings'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: RouteName.GROUP_FOLLOWERS_SETTINGS,
|
|
|
|
params: { preferredUsername: usernameWithDomain(group) },
|
|
|
|
text: $t('Followers'),
|
|
|
|
},
|
|
|
|
]"
|
|
|
|
/>
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-loading :active="loading" />
|
2021-01-20 18:16:44 +01:00
|
|
|
<section
|
2022-07-12 10:55:28 +02:00
|
|
|
class="container mx-auto section"
|
2021-03-05 11:23:17 +01:00
|
|
|
v-if="group && isCurrentActorAGroupAdmin && followers"
|
2021-01-20 18:16:44 +01:00
|
|
|
>
|
|
|
|
<h1>{{ $t("Group Followers") }} ({{ followers.total }})</h1>
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-field :label="$t('Status')" horizontal>
|
|
|
|
<o-switch v-model="pending">{{ $t("Pending") }}</o-switch>
|
|
|
|
</o-field>
|
|
|
|
<o-table
|
2021-01-20 18:16:44 +01:00
|
|
|
:data="followers.elements"
|
|
|
|
ref="queueTable"
|
2022-07-12 10:55:28 +02:00
|
|
|
:loading="loading"
|
2021-01-20 18:16:44 +01:00
|
|
|
paginated
|
|
|
|
backend-pagination
|
2022-07-12 10:55:28 +02:00
|
|
|
v-model:current-page="page"
|
2021-01-20 18:16:44 +01:00
|
|
|
:pagination-simple="true"
|
|
|
|
:aria-next-label="$t('Next page')"
|
|
|
|
:aria-previous-label="$t('Previous page')"
|
|
|
|
:aria-page-label="$t('Page')"
|
|
|
|
:aria-current-label="$t('Current page')"
|
|
|
|
:total="followers.total"
|
|
|
|
:per-page="FOLLOWERS_PER_PAGE"
|
|
|
|
backend-sorting
|
|
|
|
:default-sort-direction="'desc'"
|
|
|
|
:default-sort="['insertedAt', 'desc']"
|
2022-07-12 10:55:28 +02:00
|
|
|
@page-change="loadMoreFollowers"
|
2021-01-20 18:16:44 +01:00
|
|
|
@sort="(field, order) => $emit('sort', field, order)"
|
|
|
|
>
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-table-column
|
2021-01-20 18:16:44 +01:00
|
|
|
field="actor.preferredUsername"
|
|
|
|
:label="$t('Follower')"
|
|
|
|
v-slot="props"
|
|
|
|
>
|
2022-07-12 10:55:28 +02:00
|
|
|
<article class="flex gap-1">
|
|
|
|
<figure v-if="props.row.actor.avatar">
|
2021-01-20 18:16:44 +01:00
|
|
|
<img
|
2022-07-12 10:55:28 +02:00
|
|
|
class="rounded"
|
2021-01-20 18:16:44 +01:00
|
|
|
:src="props.row.actor.avatar.url"
|
|
|
|
alt=""
|
2022-07-12 10:55:28 +02:00
|
|
|
width="48"
|
|
|
|
height="48"
|
2021-01-20 18:16:44 +01:00
|
|
|
/>
|
|
|
|
</figure>
|
2022-07-12 10:55:28 +02:00
|
|
|
<AccountCircle v-else :size="48" />
|
|
|
|
<div class="">
|
|
|
|
<div class="">
|
2021-01-20 18:16:44 +01:00
|
|
|
<span v-if="props.row.actor.name">{{
|
|
|
|
props.row.actor.name
|
|
|
|
}}</span
|
|
|
|
><br />
|
2022-07-12 10:55:28 +02:00
|
|
|
<span class="">@{{ usernameWithDomain(props.row.actor) }}</span>
|
2021-01-20 18:16:44 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</article>
|
2022-07-12 10:55:28 +02:00
|
|
|
</o-table-column>
|
|
|
|
<o-table-column field="insertedAt" :label="$t('Date')" v-slot="props">
|
2021-01-20 18:16:44 +01:00
|
|
|
<span class="has-text-centered">
|
2022-07-12 10:55:28 +02:00
|
|
|
{{ formatDateString(props.row.insertedAt) }}<br />{{
|
|
|
|
formatTimeString(props.row.insertedAt)
|
2021-01-20 18:16:44 +01:00
|
|
|
}}
|
|
|
|
</span>
|
2022-07-12 10:55:28 +02:00
|
|
|
</o-table-column>
|
|
|
|
<o-table-column field="actions" :label="$t('Actions')" v-slot="props">
|
2021-01-20 18:16:44 +01:00
|
|
|
<div class="buttons">
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-button
|
2021-01-20 18:16:44 +01:00
|
|
|
v-if="!props.row.approved"
|
|
|
|
@click="updateFollower(props.row, true)"
|
|
|
|
icon-left="check"
|
2022-07-12 10:55:28 +02:00
|
|
|
variant="success"
|
|
|
|
>{{ $t("Accept") }}</o-button
|
2021-01-20 18:16:44 +01:00
|
|
|
>
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-button
|
2021-01-20 18:16:44 +01:00
|
|
|
@click="updateFollower(props.row, false)"
|
|
|
|
icon-left="close"
|
2022-07-12 10:55:28 +02:00
|
|
|
variant="danger"
|
|
|
|
>{{ $t("Reject") }}</o-button
|
2021-01-20 18:16:44 +01:00
|
|
|
>
|
|
|
|
</div>
|
2022-07-12 10:55:28 +02:00
|
|
|
</o-table-column>
|
|
|
|
<template #empty>
|
2021-01-20 18:16:44 +01:00
|
|
|
<empty-content icon="account" inline>
|
|
|
|
{{ $t("No follower matches the filters") }}
|
|
|
|
</empty-content>
|
|
|
|
</template>
|
2022-07-12 10:55:28 +02:00
|
|
|
</o-table>
|
2021-01-20 18:16:44 +01:00
|
|
|
</section>
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-notification v-else-if="!loading && group">
|
2021-01-20 18:16:44 +01:00
|
|
|
{{ $t("You are not an administrator for this group.") }}
|
2022-07-12 10:55:28 +02:00
|
|
|
</o-notification>
|
2021-01-20 18:16:44 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
<script lang="ts" setup>
|
2021-01-20 18:16:44 +01:00
|
|
|
import { GROUP_FOLLOWERS, UPDATE_FOLLOWER } from "@/graphql/followers";
|
|
|
|
import RouteName from "../../router/name";
|
2022-01-10 15:19:16 +01:00
|
|
|
import { displayName, usernameWithDomain } from "../../types/actor";
|
2021-01-20 18:16:44 +01:00
|
|
|
import EmptyContent from "@/components/Utils/EmptyContent.vue";
|
|
|
|
import { IFollower } from "@/types/actor/follower.model";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { useMutation, useQuery } from "@vue/apollo-composable";
|
|
|
|
import {
|
|
|
|
booleanTransformer,
|
|
|
|
integerTransformer,
|
|
|
|
useRouteQuery,
|
|
|
|
} from "vue-use-route-query";
|
|
|
|
import { computed, inject } from "vue";
|
|
|
|
import { useHead } from "@vueuse/head";
|
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
import { usePersonStatusGroup } from "@/composition/apollo/actor";
|
|
|
|
import { MemberRole } from "@/types/enums";
|
|
|
|
import { formatTimeString, formatDateString } from "@/filters/datetime";
|
|
|
|
import AccountCircle from "vue-material-design-icons/AccountCircle.vue";
|
|
|
|
import { Notifier } from "@/plugins/notifier";
|
2021-01-20 18:16:44 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const props = defineProps<{ preferredUsername: string }>();
|
2021-01-20 18:16:44 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const page = useRouteQuery("page", 1, integerTransformer);
|
2021-01-20 18:16:44 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const pending = useRouteQuery("pending", false, booleanTransformer);
|
2021-01-20 18:16:44 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const FOLLOWERS_PER_PAGE = 10;
|
2021-01-20 18:16:44 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const {
|
|
|
|
result: followersResult,
|
|
|
|
fetchMore,
|
|
|
|
loading,
|
|
|
|
} = useQuery(GROUP_FOLLOWERS, () => ({
|
|
|
|
name: props.preferredUsername,
|
|
|
|
followersPage: page.value,
|
|
|
|
followersLimit: FOLLOWERS_PER_PAGE,
|
|
|
|
approved: !pending.value,
|
|
|
|
}));
|
2021-01-20 18:16:44 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const group = computed(() => followersResult.value?.group);
|
2022-01-10 15:19:16 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const followers = computed(
|
|
|
|
() => group.value?.followers ?? { total: 0, elements: [] }
|
|
|
|
);
|
2021-01-20 18:16:44 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { t } = useI18n({ useScope: "global" });
|
2021-01-20 18:16:44 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
useHead({ title: computed(() => t("Group Followers")) });
|
2021-01-20 18:16:44 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const loadMoreFollowers = async (): Promise<void> => {
|
|
|
|
await fetchMore({
|
|
|
|
// New variables
|
|
|
|
variables: {
|
|
|
|
name: usernameWithDomain(group.value),
|
|
|
|
followersPage: page.value,
|
|
|
|
followersLimit: FOLLOWERS_PER_PAGE,
|
|
|
|
approved: !pending.value,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const notifier = inject<Notifier>("notifier");
|
2021-01-20 18:16:44 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { onDone, onError, mutate } = useMutation<{ updateFollower: IFollower }>(
|
|
|
|
UPDATE_FOLLOWER,
|
|
|
|
() => ({
|
|
|
|
refetchQueries: [
|
|
|
|
{
|
|
|
|
query: GROUP_FOLLOWERS,
|
2021-01-20 18:16:44 +01:00
|
|
|
},
|
2022-07-12 10:55:28 +02:00
|
|
|
],
|
|
|
|
})
|
|
|
|
);
|
2021-01-20 18:16:44 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
onDone(({ data }) => {
|
|
|
|
const follower = data?.updateFollower;
|
|
|
|
const message =
|
|
|
|
data?.updateFollower.approved === true
|
|
|
|
? t("@{username}'s follow request was accepted", {
|
|
|
|
username: follower?.actor.preferredUsername,
|
|
|
|
})
|
|
|
|
: t("@{username}'s follow request was rejected", {
|
|
|
|
username: follower?.actor.preferredUsername,
|
|
|
|
});
|
|
|
|
notifier?.success(message);
|
|
|
|
});
|
|
|
|
|
|
|
|
onError((error) => {
|
|
|
|
console.error(error);
|
|
|
|
if (error.graphQLErrors && error.graphQLErrors.length > 0) {
|
|
|
|
notifier?.error(error.graphQLErrors[0].message);
|
2021-01-20 18:16:44 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const updateFollower = async (
|
|
|
|
follower: IFollower,
|
|
|
|
approved: boolean
|
|
|
|
): Promise<void> => {
|
|
|
|
mutate({
|
|
|
|
id: follower.id,
|
|
|
|
approved,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const isCurrentActorAGroupAdmin = computed((): boolean => {
|
|
|
|
return hasCurrentActorThisRole(MemberRole.ADMINISTRATOR);
|
|
|
|
});
|
|
|
|
|
|
|
|
const hasCurrentActorThisRole = (givenRole: string | string[]): boolean => {
|
|
|
|
const roles = Array.isArray(givenRole) ? givenRole : [givenRole];
|
|
|
|
return (
|
|
|
|
personMemberships.value?.total > 0 &&
|
|
|
|
roles.includes(personMemberships.value?.elements[0].role)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const personMemberships = computed(
|
|
|
|
() => person.value?.memberships ?? { total: 0, elements: [] }
|
|
|
|
);
|
|
|
|
|
|
|
|
const { person } = usePersonStatusGroup(props.preferredUsername);
|
2021-01-20 18:16:44 +01:00
|
|
|
</script>
|