]>
Commit | Line | Data |
---|---|---|
41b15c89 | 1 | import { SortMeta } from 'primeng/api' |
67ed6552 C |
2 | import { Component, OnInit } from '@angular/core' |
3 | import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core' | |
e3d6c643 | 4 | import { prepareIcu } from '@app/helpers' |
073deef8 | 5 | import { AdvancedInputFilter } from '@app/shared/shared-forms' |
67ed6552 | 6 | import { InstanceFollowService } from '@app/shared/shared-instance' |
e3d6c643 | 7 | import { DropdownAction } from '@app/shared/shared-main' |
67ed6552 | 8 | import { 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 | }) |
cd940f40 | 15 | export class FollowersListComponent extends RestTable <ActorFollow> 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 | ||
cd940f40 | 23 | bulkActions: DropdownAction<ActorFollow[]>[] = [] |
073deef8 | 24 | |
51548b31 | 25 | constructor ( |
0dc64777 | 26 | private confirmService: ConfirmService, |
f8b2c1b4 | 27 | private notifier: Notifier, |
67ed6552 | 28 | private followService: InstanceFollowService |
51548b31 C |
29 | ) { |
30 | super() | |
31 | } | |
32 | ||
ab998f7b | 33 | ngOnInit () { |
24b9417c | 34 | this.initialize() |
e3d6c643 C |
35 | |
36 | this.searchFilters = this.followService.buildFollowsListFilters() | |
37 | ||
cd940f40 | 38 | this.bulkActions = [ |
e3d6c643 C |
39 | { |
40 | label: $localize`Reject`, | |
41 | handler: follows => this.rejectFollower(follows), | |
42 | isDisplayed: follows => follows.every(f => f.state !== 'rejected') | |
43 | }, | |
44 | { | |
45 | label: $localize`Accept`, | |
46 | handler: follows => this.acceptFollower(follows), | |
47 | isDisplayed: follows => follows.every(f => f.state !== 'accepted') | |
48 | }, | |
49 | { | |
50 | label: $localize`Delete`, | |
51 | handler: follows => this.deleteFollowers(follows), | |
52 | isDisplayed: follows => follows.every(f => f.state === 'rejected') | |
53 | } | |
54 | ] | |
ab998f7b C |
55 | } |
56 | ||
8e11a1b3 C |
57 | getIdentifier () { |
58 | return 'FollowersListComponent' | |
59 | } | |
60 | ||
e3d6c643 C |
61 | acceptFollower (follows: ActorFollow[]) { |
62 | this.followService.acceptFollower(follows) | |
1378c0d3 C |
63 | .subscribe({ |
64 | next: () => { | |
e3d6c643 C |
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` | |
69 | ) | |
70 | this.notifier.success(message) | |
71 | ||
72 | this.reloadData() | |
0dc64777 C |
73 | }, |
74 | ||
e3d6c643 | 75 | error: err => this.notifier.error(err.message) |
1378c0d3 | 76 | }) |
0dc64777 C |
77 | } |
78 | ||
e3d6c643 C |
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?` | |
84 | ) | |
85 | ||
66357162 | 86 | const res = await this.confirmService.confirm(message, $localize`Reject`) |
0dc64777 C |
87 | if (res === false) return |
88 | ||
e3d6c643 | 89 | this.followService.rejectFollower(follows) |
1378c0d3 C |
90 | .subscribe({ |
91 | next: () => { | |
e3d6c643 C |
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` | |
96 | ) | |
97 | this.notifier.success(message) | |
0dc64777 | 98 | |
2e46eb97 | 99 | this.reloadData() |
0dc64777 C |
100 | }, |
101 | ||
e3d6c643 | 102 | error: err => this.notifier.error(err.message) |
1378c0d3 | 103 | }) |
0dc64777 C |
104 | } |
105 | ||
e3d6c643 | 106 | async deleteFollowers (follows: ActorFollow[]) { |
cd940f40 C |
107 | const icuParams = { count: follows.length, followerName: this.buildFollowerName(follows[0]) } |
108 | ||
e3d6c643 C |
109 | let message = $localize`Deleted followers will be able to send again a follow request.` |
110 | message += '<br /><br />' | |
111 | ||
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?}}`)( | |
cd940f40 | 114 | icuParams, |
e3d6c643 C |
115 | $localize`Do you really want to delete these follow requests?` |
116 | ) | |
117 | ||
66357162 | 118 | const res = await this.confirmService.confirm(message, $localize`Delete`) |
0dc64777 C |
119 | if (res === false) return |
120 | ||
e3d6c643 | 121 | this.followService.removeFollower(follows) |
1378c0d3 C |
122 | .subscribe({ |
123 | next: () => { | |
e3d6c643 C |
124 | // eslint-disable-next-line max-len |
125 | const message = prepareIcu($localize`Removed {count, plural, =1 {{followerName} follow request} other {{count} follow requests}}`)( | |
cd940f40 | 126 | icuParams, |
e3d6c643 C |
127 | $localize`Follow requests removed` |
128 | ) | |
129 | ||
130 | this.notifier.success(message) | |
0dc64777 | 131 | |
2e46eb97 | 132 | this.reloadData() |
0dc64777 C |
133 | }, |
134 | ||
1378c0d3 C |
135 | error: err => this.notifier.error(err.message) |
136 | }) | |
0dc64777 C |
137 | } |
138 | ||
e3d6c643 C |
139 | buildFollowerName (follow: ActorFollow) { |
140 | return follow.follower.name + '@' + follow.follower.host | |
141 | } | |
142 | ||
2e46eb97 | 143 | protected reloadData () { |
b8f4167f | 144 | this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search }) |
1378c0d3 C |
145 | .subscribe({ |
146 | next: resultList => { | |
51548b31 C |
147 | this.followers = resultList.data |
148 | this.totalRecords = resultList.total | |
149 | }, | |
150 | ||
1378c0d3 C |
151 | error: err => this.notifier.error(err.message) |
152 | }) | |
51548b31 C |
153 | } |
154 | } |