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 <ActorFollow> implements OnInit {
16 followers: ActorFollow[] = []
18 sort: SortMeta = { field: 'createdAt', order: -1 }
19 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
21 searchFilters: AdvancedInputFilter[] = []
23 bulkActions: DropdownAction<ActorFollow[]>[] = []
26 private confirmService: ConfirmService,
27 private notifier: Notifier,
28 private followService: InstanceFollowService
36 this.searchFilters = this.followService.buildFollowsListFilters()
40 label: $localize`Reject`,
41 handler: follows => this.rejectFollower(follows),
42 isDisplayed: follows => follows.every(f => f.state !== 'rejected')
45 label: $localize`Accept`,
46 handler: follows => this.acceptFollower(follows),
47 isDisplayed: follows => follows.every(f => f.state !== 'accepted')
50 label: $localize`Delete`,
51 handler: follows => this.deleteFollowers(follows),
52 isDisplayed: follows => follows.every(f => f.state === 'rejected')
58 return 'FollowersListComponent'
61 acceptFollower (follows: ActorFollow[]) {
62 this.followService.acceptFollower(follows)
65 // eslint-disable-next-line max-len
66 const message = prepareIcu($localize`Accepted {count, plural, =1 {{followerName} follow request} other {{count} follow requests}}`)(
67 { count: follows.length, followerName: this.buildFollowerName(follows[0]) },
68 $localize`Follow requests accepted`
70 this.notifier.success(message)
75 error: err => this.notifier.error(err.message)
79 async rejectFollower (follows: ActorFollow[]) {
80 // eslint-disable-next-line max-len
81 const message = prepareIcu($localize`Do you really want to reject {count, plural, =1 {{followerName} follow request?} other {{count} follow requests?}}`)(
82 { count: follows.length, followerName: this.buildFollowerName(follows[0]) },
83 $localize`Do you really want to reject these follow requests?`
86 const res = await this.confirmService.confirm(message, $localize`Reject`)
87 if (res === false) return
89 this.followService.rejectFollower(follows)
92 // eslint-disable-next-line max-len
93 const message = prepareIcu($localize`Rejected {count, plural, =1 {{followerName} follow request} other {{count} follow requests}}`)(
94 { count: follows.length, followerName: this.buildFollowerName(follows[0]) },
95 $localize`Follow requests rejected`
97 this.notifier.success(message)
102 error: err => this.notifier.error(err.message)
106 async deleteFollowers (follows: ActorFollow[]) {
107 const icuParams = { count: follows.length, followerName: this.buildFollowerName(follows[0]) }
109 let message = $localize`Deleted followers will be able to send again a follow request.`
110 message += '<br /><br />'
112 // eslint-disable-next-line max-len
113 message += prepareIcu($localize`Do you really want to delete {count, plural, =1 {{followerName} follow request?} other {{count} follow requests?}}`)(
115 $localize`Do you really want to delete these follow requests?`
118 const res = await this.confirmService.confirm(message, $localize`Delete`)
119 if (res === false) return
121 this.followService.removeFollower(follows)
124 // eslint-disable-next-line max-len
125 const message = prepareIcu($localize`Removed {count, plural, =1 {{followerName} follow request} other {{count} follow requests}}`)(
127 $localize`Follow requests removed`
130 this.notifier.success(message)
135 error: err => this.notifier.error(err.message)
139 buildFollowerName (follow: ActorFollow) {
140 return follow.follower.name + '@' + follow.follower.host
143 protected reloadDataInternal () {
144 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
146 next: resultList => {
147 this.followers = resultList.data
148 this.totalRecords = resultList.total
151 error: err => this.notifier.error(err.message)