2021-03-05 11:23:17 +01:00
import {
CURRENT_ACTOR_CLIENT ,
GROUP_MEMBERSHIP_SUBSCRIPTION_CHANGED ,
2021-10-25 13:18:13 +02:00
PERSON_STATUS_GROUP ,
2021-03-05 11:23:17 +01:00
} from "@/graphql/actor" ;
2021-11-02 19:47:54 +01:00
import { DELETE_GROUP , FETCH_GROUP } from "@/graphql/group" ;
2020-10-12 12:16:36 +02:00
import RouteName from "@/router/name" ;
2021-10-25 13:18:13 +02:00
import {
IActor ,
IFollower ,
IGroup ,
IPerson ,
usernameWithDomain ,
} from "@/types/actor" ;
2020-11-27 19:27:44 +01:00
import { MemberRole } from "@/types/enums" ;
2020-10-09 15:26:37 +02:00
import { Component , Vue } from "vue-property-decorator" ;
2021-11-02 19:47:54 +01:00
import { Route } from "vue-router" ;
2020-10-09 15:26:37 +02:00
2021-06-11 15:08:43 +02:00
const now = new Date ( ) ;
2020-10-09 15:26:37 +02:00
@Component ( {
apollo : {
group : {
query : FETCH_GROUP ,
fetchPolicy : "cache-and-network" ,
variables() {
return {
name : this.$route.params.preferredUsername ,
2020-12-09 09:56:53 +01:00
beforeDateTime : null ,
2021-06-11 15:08:43 +02:00
afterDateTime : now ,
2020-10-09 15:26:37 +02:00
} ;
} ,
skip() {
return ! this . $route . params . preferredUsername ;
} ,
2020-10-12 12:16:36 +02:00
error ( { graphQLErrors } ) {
this . handleErrors ( graphQLErrors ) ;
} ,
2020-10-09 15:26:37 +02:00
} ,
person : {
2021-10-25 13:18:13 +02:00
query : PERSON_STATUS_GROUP ,
2020-10-09 15:26:37 +02:00
fetchPolicy : "cache-and-network" ,
variables() {
return {
id : this.currentActor.id ,
2021-03-29 18:23:03 +02:00
group : usernameWithDomain ( this . group ) ,
2020-10-09 15:26:37 +02:00
} ;
} ,
2020-11-06 11:34:32 +01:00
subscribeToMore : {
document : GROUP_MEMBERSHIP_SUBSCRIPTION_CHANGED ,
variables() {
return {
actorId : this.currentActor.id ,
2021-06-16 11:25:53 +02:00
group : this.group?.preferredUsername ,
2020-11-06 11:34:32 +01:00
} ;
} ,
skip() {
2021-03-05 11:23:17 +01:00
return (
! this . currentActor ||
! this . currentActor . id ||
2021-06-16 11:25:53 +02:00
! this . group ? . preferredUsername
2021-03-05 11:23:17 +01:00
) ;
2020-11-06 11:34:32 +01:00
} ,
} ,
2020-10-09 15:26:37 +02:00
skip() {
2021-03-05 11:23:17 +01:00
return (
! this . currentActor ||
! this . currentActor . id ||
2021-06-16 11:25:53 +02:00
! this . group ? . preferredUsername
2021-03-05 11:23:17 +01:00
) ;
2020-10-09 15:26:37 +02:00
} ,
} ,
currentActor : CURRENT_ACTOR_CLIENT ,
} ,
} )
export default class GroupMixin extends Vue {
2021-06-16 11:25:53 +02:00
group ! : IGroup ;
2020-10-15 14:23:55 +02:00
2020-10-09 15:26:37 +02:00
currentActor ! : IActor ;
person ! : IPerson ;
get isCurrentActorAGroupAdmin ( ) : boolean {
2020-10-22 09:37:30 +02:00
return this . hasCurrentActorThisRole ( MemberRole . ADMINISTRATOR ) ;
}
get isCurrentActorAGroupModerator ( ) : boolean {
2020-11-30 10:24:11 +01:00
return this . hasCurrentActorThisRole ( [
MemberRole . MODERATOR ,
MemberRole . ADMINISTRATOR ,
] ) ;
2020-10-22 09:37:30 +02:00
}
2021-08-05 11:01:40 +02:00
get isCurrentActorAGroupMember ( ) : boolean {
return this . hasCurrentActorThisRole ( [
MemberRole . MODERATOR ,
MemberRole . ADMINISTRATOR ,
MemberRole . MEMBER ,
] ) ;
}
2021-11-12 15:42:52 +01:00
get isCurrentActorAPendingGroupMember ( ) : boolean {
return this . hasCurrentActorThisRole ( [ MemberRole . NOT_APPROVED ] ) ;
}
2020-10-22 09:37:30 +02:00
hasCurrentActorThisRole ( givenRole : string | string [ ] ) : boolean {
const roles = Array . isArray ( givenRole ) ? givenRole : [ givenRole ] ;
2021-03-16 17:36:30 +01:00
return (
this . person ? . memberships ? . total > 0 &&
roles . includes ( this . person ? . memberships ? . elements [ 0 ] . role )
) ;
2020-10-09 15:26:37 +02:00
}
2020-10-12 12:16:36 +02:00
2021-10-25 13:18:13 +02:00
get isCurrentActorFollowing ( ) : boolean {
2021-10-25 16:53:46 +02:00
return this . currentActorFollow ? . approved === true ;
}
get isCurrentActorPendingFollow ( ) : boolean {
return this . currentActorFollow ? . approved === false ;
2021-10-25 13:18:13 +02:00
}
get isCurrentActorFollowingNotify ( ) : boolean {
2021-10-25 16:53:46 +02:00
return (
this . isCurrentActorFollowing && this . currentActorFollow ? . notify === true
) ;
2021-10-25 13:18:13 +02:00
}
get currentActorFollow ( ) : IFollower | null {
if ( this . person ? . follows ? . total > 0 ) {
return this . person ? . follows ? . elements [ 0 ] ;
}
return null ;
}
2020-10-15 14:23:55 +02:00
handleErrors ( errors : any [ ] ) : void {
2020-10-12 12:16:36 +02:00
if (
errors . some ( ( error ) = > error . status_code === 404 ) ||
errors . some ( ( { message } ) = > message . includes ( "has invalid value $uuid" ) )
) {
this . $router . replace ( { name : RouteName.PAGE_NOT_FOUND } ) ;
}
}
2021-11-02 19:47:54 +01:00
confirmDeleteGroup ( ) : void {
this . $buefy . dialog . confirm ( {
title : this.$t ( "Delete group" ) as string ,
message : this.$t (
"Are you sure you want to <b>completely delete</b> this group? All members - including remote ones - will be notified and removed from the group, and <b>all of the group data (events, posts, discussions, todos…) will be irretrievably destroyed</b>."
) as string ,
confirmText : this.$t ( "Delete group" ) as string ,
cancelText : this.$t ( "Cancel" ) as string ,
type : "is-danger" ,
hasIcon : true ,
onConfirm : ( ) = > this . deleteGroup ( ) ,
} ) ;
}
async deleteGroup ( ) : Promise < Route > {
await this . $apollo . mutate < { deleteGroup : IGroup } > ( {
mutation : DELETE_GROUP ,
variables : {
groupId : this.group.id ,
} ,
} ) ;
return this . $router . push ( { name : RouteName.MY_GROUPS } ) ;
}
2020-10-09 15:26:37 +02:00
}