1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit } from '@angular/core'
3 import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
4 import { prepareIcu } from '@app/helpers'
5 import { AdvancedInputFilter } from '@app/shared/shared-forms'
6 import { InstanceFollowService } from '@app/shared/shared-instance'
7 import { DropdownAction } from '@app/shared/shared-main'
8 import { ActorFollow } from '@shared/models'
11 selector: 'my-followers-list',
12 templateUrl: './followers-list.component.html',
13 styleUrls: [ './followers-list.component.scss' ]
15 export class FollowersListComponent extends RestTable implements OnInit {
16 followers: ActorFollow[] = []
18 sort: SortMeta = { field: 'createdAt', order: -1 }
19 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
21 searchFilters: AdvancedInputFilter[] = []
23 selectedFollows: ActorFollow[] = []
24 bulkFollowsActions: DropdownAction<ActorFollow[]>[] = []
27 private confirmService: ConfirmService,
28 private notifier: Notifier,
29 private followService: InstanceFollowService
37 this.searchFilters = this.followService.buildFollowsListFilters()
39 this.bulkFollowsActions = [
41 label: $localize`Reject`,
42 handler: follows => this.rejectFollower(follows),
43 isDisplayed: follows => follows.every(f => f.state !== 'rejected')
46 label: $localize`Accept`,
47 handler: follows => this.acceptFollower(follows),
48 isDisplayed: follows => follows.every(f => f.state !== 'accepted')
51 label: $localize`Delete`,
52 handler: follows => this.deleteFollowers(follows),
53 isDisplayed: follows => follows.every(f => f.state === 'rejected')
59 return 'FollowersListComponent'
62 acceptFollower (follows: ActorFollow[]) {
63 this.followService.acceptFollower(follows)
66 // eslint-disable-next-line max-len
67 const message = prepareIcu($localize`Accepted {count, plural, =1 {{followerName} follow request} other {{count} follow requests}}`)(
68 { count: follows.length, followerName: this.buildFollowerName(follows[0]) },
69 $localize`Follow requests accepted`
71 this.notifier.success(message)
76 error: err => this.notifier.error(err.message)
80 async rejectFollower (follows: ActorFollow[]) {
81 // eslint-disable-next-line max-len
82 const message = prepareIcu($localize`Do you really want to reject {count, plural, =1 {{followerName} follow request?} other {{count} follow requests?}}`)(
83 { count: follows.length, followerName: this.buildFollowerName(follows[0]) },
84 $localize`Do you really want to reject these follow requests?`
87 const res = await this.confirmService.confirm(message, $localize`Reject`)
88 if (res === false) return
90 this.followService.rejectFollower(follows)
93 // eslint-disable-next-line max-len
94 const message = prepareIcu($localize`Rejected {count, plural, =1 {{followerName} follow request} other {{count} follow requests}}`)(
95 { count: follows.length, followerName: this.buildFollowerName(follows[0]) },
96 $localize`Follow requests rejected`
98 this.notifier.success(message)
103 error: err => this.notifier.error(err.message)
107 async deleteFollowers (follows: ActorFollow[]) {
108 let message = $localize`Deleted followers will be able to send again a follow request.`
109 message += '<br /><br />'
111 // eslint-disable-next-line max-len
112 message += prepareIcu($localize`Do you really want to delete {count, plural, =1 {{followerName} follow request?} other {{count} follow requests?}}`)(
113 { count: follows.length, followerName: this.buildFollowerName(follows[0]) },
114 $localize`Do you really want to delete these follow requests?`
117 const res = await this.confirmService.confirm(message, $localize`Delete`)
118 if (res === false) return
120 this.followService.removeFollower(follows)
123 // eslint-disable-next-line max-len
124 const message = prepareIcu($localize`Removed {count, plural, =1 {{followerName} follow request} other {{count} follow requests}}`)(
125 { count: follows.length, followerName: this.buildFollowerName(follows[0]) },
126 $localize`Follow requests removed`
129 this.notifier.success(message)
134 error: err => this.notifier.error(err.message)
138 buildFollowerName (follow: ActorFollow) {
139 return follow.follower.name + '@' + follow.follower.host
142 isInSelectionMode () {
143 return this.selectedFollows.length !== 0
146 protected reloadData () {
147 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
149 next: resultList => {
150 this.followers = resultList.data
151 this.totalRecords = resultList.total
154 error: err => this.notifier.error(err.message)