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