Get membership status only for the current group
Closes #575 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -446,6 +446,70 @@ export const PERSON_MEMBERSHIPS_WITH_MEMBERS = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
export const PERSON_MEMBERSHIP_GROUP = gql`
|
||||
query PersonMembershipGroup($id: ID!, $group: String!) {
|
||||
person(id: $id) {
|
||||
id
|
||||
memberships(group: $group) {
|
||||
total
|
||||
elements {
|
||||
id
|
||||
role
|
||||
parent {
|
||||
id
|
||||
preferredUsername
|
||||
name
|
||||
domain
|
||||
avatar {
|
||||
id
|
||||
url
|
||||
}
|
||||
}
|
||||
invitedBy {
|
||||
id
|
||||
preferredUsername
|
||||
name
|
||||
}
|
||||
insertedAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const GROUP_MEMBERSHIP_SUBSCRIPTION_CHANGED = gql`
|
||||
subscription($actorId: ID!, $group: String!) {
|
||||
groupMembershipChanged(personId: $actorId, group: $group) {
|
||||
id
|
||||
memberships {
|
||||
total
|
||||
elements {
|
||||
id
|
||||
role
|
||||
parent {
|
||||
id
|
||||
preferredUsername
|
||||
name
|
||||
domain
|
||||
avatar {
|
||||
id
|
||||
url
|
||||
}
|
||||
}
|
||||
invitedBy {
|
||||
id
|
||||
preferredUsername
|
||||
name
|
||||
}
|
||||
insertedAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const CREATE_PERSON = gql`
|
||||
mutation CreatePerson(
|
||||
$preferredUsername: String!
|
||||
|
||||
@@ -592,38 +592,6 @@ export const EVENT_PERSON_PARTICIPATION_SUBSCRIPTION_CHANGED = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
export const GROUP_MEMBERSHIP_SUBSCRIPTION_CHANGED = gql`
|
||||
subscription($actorId: ID!) {
|
||||
groupMembershipChanged(personId: $actorId) {
|
||||
id
|
||||
memberships {
|
||||
total
|
||||
elements {
|
||||
id
|
||||
role
|
||||
parent {
|
||||
id
|
||||
preferredUsername
|
||||
name
|
||||
domain
|
||||
avatar {
|
||||
id
|
||||
url
|
||||
}
|
||||
}
|
||||
invitedBy {
|
||||
id
|
||||
preferredUsername
|
||||
name
|
||||
}
|
||||
insertedAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const FETCH_GROUP_EVENTS = gql`
|
||||
query(
|
||||
$name: String!
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { PERSON_MEMBERSHIPS, CURRENT_ACTOR_CLIENT } from "@/graphql/actor";
|
||||
import { GROUP_MEMBERSHIP_SUBSCRIPTION_CHANGED } from "@/graphql/event";
|
||||
import {
|
||||
CURRENT_ACTOR_CLIENT,
|
||||
GROUP_MEMBERSHIP_SUBSCRIPTION_CHANGED,
|
||||
PERSON_MEMBERSHIP_GROUP,
|
||||
} from "@/graphql/actor";
|
||||
import { FETCH_GROUP } from "@/graphql/group";
|
||||
import RouteName from "@/router/name";
|
||||
import { Group, IActor, IGroup, IPerson } from "@/types/actor";
|
||||
@@ -26,11 +29,12 @@ import { Component, Vue } from "vue-property-decorator";
|
||||
},
|
||||
},
|
||||
person: {
|
||||
query: PERSON_MEMBERSHIPS,
|
||||
query: PERSON_MEMBERSHIP_GROUP,
|
||||
fetchPolicy: "cache-and-network",
|
||||
variables() {
|
||||
return {
|
||||
id: this.currentActor.id,
|
||||
group: this.$route.params.preferredUsername,
|
||||
};
|
||||
},
|
||||
subscribeToMore: {
|
||||
@@ -38,14 +42,23 @@ import { Component, Vue } from "vue-property-decorator";
|
||||
variables() {
|
||||
return {
|
||||
actorId: this.currentActor.id,
|
||||
group: this.$route.params.preferredUsername,
|
||||
};
|
||||
},
|
||||
skip() {
|
||||
return !this.currentActor || !this.currentActor.id;
|
||||
return (
|
||||
!this.currentActor ||
|
||||
!this.currentActor.id ||
|
||||
!this.$route.params.preferredUsername
|
||||
);
|
||||
},
|
||||
},
|
||||
skip() {
|
||||
return !this.currentActor || !this.currentActor.id;
|
||||
return (
|
||||
!this.currentActor ||
|
||||
!this.currentActor.id ||
|
||||
!this.$route.params.preferredUsername
|
||||
);
|
||||
},
|
||||
},
|
||||
currentActor: CURRENT_ACTOR_CLIENT,
|
||||
@@ -71,13 +84,7 @@ export default class GroupMixin extends Vue {
|
||||
|
||||
hasCurrentActorThisRole(givenRole: string | string[]): boolean {
|
||||
const roles = Array.isArray(givenRole) ? givenRole : [givenRole];
|
||||
return (
|
||||
this.person &&
|
||||
this.person.memberships.elements.some(
|
||||
({ parent: { id }, role }) =>
|
||||
id === this.group.id && roles.includes(role)
|
||||
)
|
||||
);
|
||||
return roles.includes(this.person?.memberships?.elements[0].role);
|
||||
}
|
||||
|
||||
handleErrors(errors: any[]): void {
|
||||
|
||||
@@ -75,8 +75,11 @@ import { IActor, IGroup, IPerson, usernameWithDomain } from "@/types/actor";
|
||||
import DiscussionListItem from "@/components/Discussion/DiscussionListItem.vue";
|
||||
import RouteName from "../../router/name";
|
||||
import { MemberRole } from "@/types/enums";
|
||||
import { CURRENT_ACTOR_CLIENT, PERSON_MEMBERSHIPS } from "@/graphql/actor";
|
||||
import { GROUP_MEMBERSHIP_SUBSCRIPTION_CHANGED } from "@/graphql/event";
|
||||
import {
|
||||
CURRENT_ACTOR_CLIENT,
|
||||
GROUP_MEMBERSHIP_SUBSCRIPTION_CHANGED,
|
||||
PERSON_MEMBERSHIP_GROUP,
|
||||
} from "@/graphql/actor";
|
||||
import { IMember } from "@/types/actor/member.model";
|
||||
import EmptyContent from "@/components/Utils/EmptyContent.vue";
|
||||
|
||||
@@ -96,11 +99,12 @@ import EmptyContent from "@/components/Utils/EmptyContent.vue";
|
||||
},
|
||||
},
|
||||
person: {
|
||||
query: PERSON_MEMBERSHIPS,
|
||||
query: PERSON_MEMBERSHIP_GROUP,
|
||||
fetchPolicy: "cache-and-network",
|
||||
variables() {
|
||||
return {
|
||||
id: this.currentActor.id,
|
||||
group: this.preferredUsername,
|
||||
};
|
||||
},
|
||||
subscribeToMore: {
|
||||
@@ -108,14 +112,21 @@ import EmptyContent from "@/components/Utils/EmptyContent.vue";
|
||||
variables() {
|
||||
return {
|
||||
actorId: this.currentActor.id,
|
||||
group: this.preferredUsername,
|
||||
};
|
||||
},
|
||||
skip() {
|
||||
return !this.currentActor || !this.currentActor.id;
|
||||
return (
|
||||
!this.currentActor ||
|
||||
!this.currentActor.id ||
|
||||
!this.preferredUsername
|
||||
);
|
||||
},
|
||||
},
|
||||
skip() {
|
||||
return !this.currentActor || !this.currentActor.id;
|
||||
return (
|
||||
!this.currentActor || !this.currentActor.id || !this.preferredUsername
|
||||
);
|
||||
},
|
||||
},
|
||||
currentActor: CURRENT_ACTOR_CLIENT,
|
||||
|
||||
@@ -628,15 +628,14 @@ export default class Group extends mixins(GroupMixin) {
|
||||
}
|
||||
|
||||
get groupMember(): IMember | undefined {
|
||||
if (!this.person || !this.person.id) return undefined;
|
||||
return this.person.memberships.elements.find(
|
||||
({ parent: { id } }) => id === this.group.id
|
||||
);
|
||||
if (this.person?.memberships?.total > 0) {
|
||||
return this.person?.memberships?.elements[0];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
get groupMemberships(): (string | undefined)[] {
|
||||
if (!this.person || !this.person.id) return [];
|
||||
return this.person.memberships.elements
|
||||
return this.person?.memberships?.elements
|
||||
.filter(
|
||||
(membership: IMember) =>
|
||||
![
|
||||
|
||||
@@ -33,14 +33,13 @@
|
||||
</nav>
|
||||
<section
|
||||
class="container section"
|
||||
v-if="group && isCurrentActorAGroupAdmin"
|
||||
v-if="group && isCurrentActorAGroupAdmin && followers"
|
||||
>
|
||||
<h1>{{ $t("Group Followers") }} ({{ followers.total }})</h1>
|
||||
<b-field :label="$t('Status')" horizontal>
|
||||
<b-switch v-model="pending">{{ $t("Pending") }}</b-switch>
|
||||
</b-field>
|
||||
<b-table
|
||||
v-if="followers"
|
||||
:data="followers.elements"
|
||||
ref="queueTable"
|
||||
:loading="this.$apollo.loading"
|
||||
|
||||
Reference in New Issue
Block a user