1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit } from '@angular/core'
3 import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
4 import { AdvancedInputFilter } from '@app/shared/shared-forms'
5 import { InstanceFollowService } from '@app/shared/shared-instance'
6 import { ActorFollow } from '@shared/models'
9 selector: 'my-followers-list',
10 templateUrl: './followers-list.component.html',
11 styleUrls: [ './followers-list.component.scss' ]
13 export class FollowersListComponent extends RestTable implements OnInit {
14 followers: ActorFollow[] = []
16 sort: SortMeta = { field: 'createdAt', order: -1 }
17 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
19 searchFilters: AdvancedInputFilter[]
22 private confirmService: ConfirmService,
23 private notifier: Notifier,
24 private followService: InstanceFollowService
28 this.searchFilters = this.followService.buildFollowsListFilters()
36 return 'FollowersListComponent'
39 acceptFollower (follow: ActorFollow) {
40 follow.state = 'accepted'
42 this.followService.acceptFollower(follow)
45 const handle = follow.follower.name + '@' + follow.follower.host
46 this.notifier.success($localize`${handle} accepted in instance followers`)
50 follow.state = 'pending'
51 this.notifier.error(err.message)
56 async rejectFollower (follow: ActorFollow) {
57 const message = $localize`Do you really want to reject this follower?`
58 const res = await this.confirmService.confirm(message, $localize`Reject`)
59 if (res === false) return
61 this.followService.rejectFollower(follow)
64 const handle = follow.follower.name + '@' + follow.follower.host
65 this.notifier.success($localize`${handle} rejected from instance followers`)
71 follow.state = 'pending'
72 this.notifier.error(err.message)
77 async deleteFollower (follow: ActorFollow) {
78 const message = $localize`Do you really want to delete this follower? It will be able to send again another follow request.`
79 const res = await this.confirmService.confirm(message, $localize`Delete`)
80 if (res === false) return
82 this.followService.removeFollower(follow)
85 const handle = follow.follower.name + '@' + follow.follower.host
86 this.notifier.success($localize`${handle} removed from instance followers`)
91 error: err => this.notifier.error(err.message)
95 protected reloadData () {
96 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
99 this.followers = resultList.data
100 this.totalRecords = resultList.total
103 error: err => this.notifier.error(err.message)