]>
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' | |
4 | import { InstanceFollowService } from '@app/shared/shared-instance' | |
b1d40cff | 5 | import { I18n } from '@ngx-translate/i18n-polyfill' |
67ed6552 | 6 | import { ActorFollow } from '@shared/models' |
51548b31 C |
7 | |
8 | @Component({ | |
9 | selector: 'my-followers-list', | |
10 | templateUrl: './followers-list.component.html', | |
d3840613 | 11 | styleUrls: [ '../follows.component.scss', './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 | ||
19 | constructor ( | |
0dc64777 | 20 | private confirmService: ConfirmService, |
f8b2c1b4 | 21 | private notifier: Notifier, |
0dc64777 | 22 | private i18n: I18n, |
67ed6552 | 23 | private followService: InstanceFollowService |
51548b31 C |
24 | ) { |
25 | super() | |
26 | } | |
27 | ||
ab998f7b | 28 | ngOnInit () { |
24b9417c | 29 | this.initialize() |
ab998f7b C |
30 | } |
31 | ||
8e11a1b3 C |
32 | getIdentifier () { |
33 | return 'FollowersListComponent' | |
34 | } | |
35 | ||
0dc64777 C |
36 | acceptFollower (follow: ActorFollow) { |
37 | follow.state = 'accepted' | |
38 | ||
39 | this.followService.acceptFollower(follow) | |
40 | .subscribe( | |
41 | () => { | |
42 | const handle = follow.follower.name + '@' + follow.follower.host | |
43 | this.notifier.success(this.i18n('{{handle}} accepted in instance followers', { handle })) | |
44 | }, | |
45 | ||
46 | err => { | |
47 | follow.state = 'pending' | |
48 | this.notifier.error(err.message) | |
49 | } | |
50 | ) | |
51 | } | |
52 | ||
53 | async rejectFollower (follow: ActorFollow) { | |
54 | const message = this.i18n('Do you really want to reject this follower?') | |
55 | const res = await this.confirmService.confirm(message, this.i18n('Reject')) | |
56 | if (res === false) return | |
57 | ||
58 | this.followService.rejectFollower(follow) | |
59 | .subscribe( | |
60 | () => { | |
61 | const handle = follow.follower.name + '@' + follow.follower.host | |
62 | this.notifier.success(this.i18n('{{handle}} rejected from instance followers', { handle })) | |
63 | ||
64 | this.loadData() | |
65 | }, | |
66 | ||
67 | err => { | |
68 | follow.state = 'pending' | |
69 | this.notifier.error(err.message) | |
70 | } | |
71 | ) | |
72 | } | |
73 | ||
74 | async deleteFollower (follow: ActorFollow) { | |
75 | const message = this.i18n('Do you really want to delete this follower?') | |
76 | const res = await this.confirmService.confirm(message, this.i18n('Delete')) | |
77 | if (res === false) return | |
78 | ||
79 | this.followService.removeFollower(follow) | |
80 | .subscribe( | |
81 | () => { | |
82 | const handle = follow.follower.name + '@' + follow.follower.host | |
83 | this.notifier.success(this.i18n('{{handle}} removed from instance followers', { handle })) | |
84 | ||
85 | this.loadData() | |
86 | }, | |
87 | ||
88 | err => this.notifier.error(err.message) | |
89 | ) | |
90 | } | |
91 | ||
51548b31 | 92 | protected loadData () { |
b8f4167f | 93 | this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search }) |
51548b31 C |
94 | .subscribe( |
95 | resultList => { | |
96 | this.followers = resultList.data | |
97 | this.totalRecords = resultList.total | |
98 | }, | |
99 | ||
f8b2c1b4 | 100 | err => this.notifier.error(err.message) |
51548b31 C |
101 | ) |
102 | } | |
103 | } |