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