]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/follows/followers-list/followers-list.component.ts
Update build steps for localization
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / followers-list / followers-list.component.ts
1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit } from '@angular/core'
3 import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
4 import { InstanceFollowService } from '@app/shared/shared-instance'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { ActorFollow } from '@shared/models'
7
8 @Component({
9 selector: 'my-followers-list',
10 templateUrl: './followers-list.component.html',
11 styleUrls: [ '../follows.component.scss', './followers-list.component.scss' ]
12 })
13 export class FollowersListComponent extends RestTable implements OnInit {
14 followers: ActorFollow[] = []
15 totalRecords = 0
16 sort: SortMeta = { field: 'createdAt', order: -1 }
17 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
18
19 constructor (
20 private confirmService: ConfirmService,
21 private notifier: Notifier,
22 private i18n: I18n,
23 private followService: InstanceFollowService
24 ) {
25 super()
26 }
27
28 ngOnInit () {
29 this.initialize()
30 }
31
32 getIdentifier () {
33 return 'FollowersListComponent'
34 }
35
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
92 protected loadData () {
93 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
94 .subscribe(
95 resultList => {
96 this.followers = resultList.data
97 this.totalRecords = resultList.total
98 },
99
100 err => this.notifier.error(err.message)
101 )
102 }
103 }