]>
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' | |
073deef8 | 4 | import { AdvancedInputFilter } from '@app/shared/shared-forms' |
67ed6552 | 5 | import { InstanceFollowService } from '@app/shared/shared-instance' |
67ed6552 | 6 | import { ActorFollow } from '@shared/models' |
51548b31 C |
7 | |
8 | @Component({ | |
9 | selector: 'my-followers-list', | |
10 | templateUrl: './followers-list.component.html', | |
eeae8142 | 11 | styleUrls: [ './followers-list.component.scss' ] |
51548b31 | 12 | }) |
ab998f7b | 13 | export class FollowersListComponent extends RestTable implements OnInit { |
c48e82b5 | 14 | followers: ActorFollow[] = [] |
51548b31 | 15 | totalRecords = 0 |
bb152476 | 16 | sort: SortMeta = { field: 'createdAt', order: -1 } |
51548b31 C |
17 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
18 | ||
073deef8 C |
19 | searchFilters: AdvancedInputFilter[] |
20 | ||
51548b31 | 21 | constructor ( |
0dc64777 | 22 | private confirmService: ConfirmService, |
f8b2c1b4 | 23 | private notifier: Notifier, |
67ed6552 | 24 | private followService: InstanceFollowService |
51548b31 C |
25 | ) { |
26 | super() | |
073deef8 C |
27 | |
28 | this.searchFilters = this.followService.buildFollowsListFilters() | |
51548b31 C |
29 | } |
30 | ||
ab998f7b | 31 | ngOnInit () { |
24b9417c | 32 | this.initialize() |
ab998f7b C |
33 | } |
34 | ||
8e11a1b3 C |
35 | getIdentifier () { |
36 | return 'FollowersListComponent' | |
37 | } | |
38 | ||
0dc64777 C |
39 | acceptFollower (follow: ActorFollow) { |
40 | follow.state = 'accepted' | |
41 | ||
42 | this.followService.acceptFollower(follow) | |
1378c0d3 C |
43 | .subscribe({ |
44 | next: () => { | |
0dc64777 | 45 | const handle = follow.follower.name + '@' + follow.follower.host |
66357162 | 46 | this.notifier.success($localize`${handle} accepted in instance followers`) |
0dc64777 C |
47 | }, |
48 | ||
1378c0d3 | 49 | error: err => { |
0dc64777 C |
50 | follow.state = 'pending' |
51 | this.notifier.error(err.message) | |
52 | } | |
1378c0d3 | 53 | }) |
0dc64777 C |
54 | } |
55 | ||
56 | async rejectFollower (follow: ActorFollow) { | |
66357162 C |
57 | const message = $localize`Do you really want to reject this follower?` |
58 | const res = await this.confirmService.confirm(message, $localize`Reject`) | |
0dc64777 C |
59 | if (res === false) return |
60 | ||
61 | this.followService.rejectFollower(follow) | |
1378c0d3 C |
62 | .subscribe({ |
63 | next: () => { | |
0dc64777 | 64 | const handle = follow.follower.name + '@' + follow.follower.host |
66357162 | 65 | this.notifier.success($localize`${handle} rejected from instance followers`) |
0dc64777 | 66 | |
2e46eb97 | 67 | this.reloadData() |
0dc64777 C |
68 | }, |
69 | ||
1378c0d3 | 70 | error: err => { |
0dc64777 C |
71 | follow.state = 'pending' |
72 | this.notifier.error(err.message) | |
73 | } | |
1378c0d3 | 74 | }) |
0dc64777 C |
75 | } |
76 | ||
77 | async deleteFollower (follow: ActorFollow) { | |
073deef8 | 78 | const message = $localize`Do you really want to delete this follower? It will be able to send again another follow request.` |
66357162 | 79 | const res = await this.confirmService.confirm(message, $localize`Delete`) |
0dc64777 C |
80 | if (res === false) return |
81 | ||
82 | this.followService.removeFollower(follow) | |
1378c0d3 C |
83 | .subscribe({ |
84 | next: () => { | |
0dc64777 | 85 | const handle = follow.follower.name + '@' + follow.follower.host |
66357162 | 86 | this.notifier.success($localize`${handle} removed from instance followers`) |
0dc64777 | 87 | |
2e46eb97 | 88 | this.reloadData() |
0dc64777 C |
89 | }, |
90 | ||
1378c0d3 C |
91 | error: err => this.notifier.error(err.message) |
92 | }) | |
0dc64777 C |
93 | } |
94 | ||
2e46eb97 | 95 | protected reloadData () { |
b8f4167f | 96 | this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search }) |
1378c0d3 C |
97 | .subscribe({ |
98 | next: resultList => { | |
51548b31 C |
99 | this.followers = resultList.data |
100 | this.totalRecords = resultList.total | |
101 | }, | |
102 | ||
1378c0d3 C |
103 | error: err => this.notifier.error(err.message) |
104 | }) | |
51548b31 C |
105 | } |
106 | } |