1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit } from '@angular/core'
3 import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
4 import { InstanceFollowService } from '@app/shared/shared-instance'
5 import { ActorFollow } from '@shared/models'
8 selector: 'my-followers-list',
9 templateUrl: './followers-list.component.html',
10 styleUrls: [ '../follows.component.scss', './followers-list.component.scss' ]
12 export class FollowersListComponent extends RestTable implements OnInit {
13 followers: ActorFollow[] = []
15 sort: SortMeta = { field: 'createdAt', order: -1 }
16 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
19 private confirmService: ConfirmService,
20 private notifier: Notifier,
21 private followService: InstanceFollowService
31 return 'FollowersListComponent'
34 acceptFollower (follow: ActorFollow) {
35 follow.state = 'accepted'
37 this.followService.acceptFollower(follow)
40 const handle = follow.follower.name + '@' + follow.follower.host
41 this.notifier.success($localize`${handle} accepted in instance followers`)
45 follow.state = 'pending'
46 this.notifier.error(err.message)
51 async rejectFollower (follow: ActorFollow) {
52 const message = $localize`Do you really want to reject this follower?`
53 const res = await this.confirmService.confirm(message, $localize`Reject`)
54 if (res === false) return
56 this.followService.rejectFollower(follow)
59 const handle = follow.follower.name + '@' + follow.follower.host
60 this.notifier.success($localize`${handle} rejected from instance followers`)
66 follow.state = 'pending'
67 this.notifier.error(err.message)
72 async deleteFollower (follow: ActorFollow) {
73 const message = $localize`Do you really want to delete this follower?`
74 const res = await this.confirmService.confirm(message, $localize`Delete`)
75 if (res === false) return
77 this.followService.removeFollower(follow)
80 const handle = follow.follower.name + '@' + follow.follower.host
81 this.notifier.success($localize`${handle} removed from instance followers`)
86 err => this.notifier.error(err.message)
90 protected reloadData () {
91 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
94 this.followers = resultList.data
95 this.totalRecords = resultList.total
98 err => this.notifier.error(err.message)