]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/follows/followers-list/followers-list.component.ts
Merge branch 'release/4.3.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / followers-list / followers-list.component.ts
CommitLineData
41b15c89 1import { SortMeta } from 'primeng/api'
67ed6552
C
2import { Component, OnInit } from '@angular/core'
3import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
e3d6c643 4import { prepareIcu } from '@app/helpers'
073deef8 5import { AdvancedInputFilter } from '@app/shared/shared-forms'
67ed6552 6import { InstanceFollowService } from '@app/shared/shared-instance'
e3d6c643 7import { DropdownAction } from '@app/shared/shared-main'
67ed6552 8import { ActorFollow } from '@shared/models'
51548b31
C
9
10@Component({
11 selector: 'my-followers-list',
12 templateUrl: './followers-list.component.html',
eeae8142 13 styleUrls: [ './followers-list.component.scss' ]
51548b31 14})
ab998f7b 15export class FollowersListComponent extends RestTable implements OnInit {
c48e82b5 16 followers: ActorFollow[] = []
51548b31 17 totalRecords = 0
bb152476 18 sort: SortMeta = { field: 'createdAt', order: -1 }
51548b31
C
19 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
20
e3d6c643
C
21 searchFilters: AdvancedInputFilter[] = []
22
23 selectedFollows: ActorFollow[] = []
24 bulkFollowsActions: DropdownAction<ActorFollow[]>[] = []
073deef8 25
51548b31 26 constructor (
0dc64777 27 private confirmService: ConfirmService,
f8b2c1b4 28 private notifier: Notifier,
67ed6552 29 private followService: InstanceFollowService
51548b31
C
30 ) {
31 super()
32 }
33
ab998f7b 34 ngOnInit () {
24b9417c 35 this.initialize()
e3d6c643
C
36
37 this.searchFilters = this.followService.buildFollowsListFilters()
38
39 this.bulkFollowsActions = [
40 {
41 label: $localize`Reject`,
42 handler: follows => this.rejectFollower(follows),
43 isDisplayed: follows => follows.every(f => f.state !== 'rejected')
44 },
45 {
46 label: $localize`Accept`,
47 handler: follows => this.acceptFollower(follows),
48 isDisplayed: follows => follows.every(f => f.state !== 'accepted')
49 },
50 {
51 label: $localize`Delete`,
52 handler: follows => this.deleteFollowers(follows),
53 isDisplayed: follows => follows.every(f => f.state === 'rejected')
54 }
55 ]
ab998f7b
C
56 }
57
8e11a1b3
C
58 getIdentifier () {
59 return 'FollowersListComponent'
60 }
61
e3d6c643
C
62 acceptFollower (follows: ActorFollow[]) {
63 this.followService.acceptFollower(follows)
1378c0d3
C
64 .subscribe({
65 next: () => {
e3d6c643
C
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`
70 )
71 this.notifier.success(message)
72
73 this.reloadData()
0dc64777
C
74 },
75
e3d6c643 76 error: err => this.notifier.error(err.message)
1378c0d3 77 })
0dc64777
C
78 }
79
e3d6c643
C
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?`
85 )
86
66357162 87 const res = await this.confirmService.confirm(message, $localize`Reject`)
0dc64777
C
88 if (res === false) return
89
e3d6c643 90 this.followService.rejectFollower(follows)
1378c0d3
C
91 .subscribe({
92 next: () => {
e3d6c643
C
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`
97 )
98 this.notifier.success(message)
0dc64777 99
2e46eb97 100 this.reloadData()
0dc64777
C
101 },
102
e3d6c643 103 error: err => this.notifier.error(err.message)
1378c0d3 104 })
0dc64777
C
105 }
106
e3d6c643
C
107 async deleteFollowers (follows: ActorFollow[]) {
108 let message = $localize`Deleted followers will be able to send again a follow request.`
109 message += '<br /><br />'
110
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?`
115 )
116
66357162 117 const res = await this.confirmService.confirm(message, $localize`Delete`)
0dc64777
C
118 if (res === false) return
119
e3d6c643 120 this.followService.removeFollower(follows)
1378c0d3
C
121 .subscribe({
122 next: () => {
e3d6c643
C
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`
127 )
128
129 this.notifier.success(message)
0dc64777 130
2e46eb97 131 this.reloadData()
0dc64777
C
132 },
133
1378c0d3
C
134 error: err => this.notifier.error(err.message)
135 })
0dc64777
C
136 }
137
e3d6c643
C
138 buildFollowerName (follow: ActorFollow) {
139 return follow.follower.name + '@' + follow.follower.host
140 }
141
142 isInSelectionMode () {
143 return this.selectedFollows.length !== 0
144 }
145
2e46eb97 146 protected reloadData () {
b8f4167f 147 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
1378c0d3
C
148 .subscribe({
149 next: resultList => {
51548b31
C
150 this.followers = resultList.data
151 this.totalRecords = resultList.total
152 },
153
1378c0d3
C
154 error: err => this.notifier.error(err.message)
155 })
51548b31
C
156 }
157}