]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/follows/followers-list/followers-list.component.ts
Migrate to $localize
[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 { ActorFollow } from '@shared/models'
6
7 @Component({
8 selector: 'my-followers-list',
9 templateUrl: './followers-list.component.html',
10 styleUrls: [ '../follows.component.scss', './followers-list.component.scss' ]
11 })
12 export class FollowersListComponent extends RestTable implements OnInit {
13 followers: ActorFollow[] = []
14 totalRecords = 0
15 sort: SortMeta = { field: 'createdAt', order: -1 }
16 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
17
18 constructor (
19 private confirmService: ConfirmService,
20 private notifier: Notifier,
21 private followService: InstanceFollowService
22 ) {
23 super()
24 }
25
26 ngOnInit () {
27 this.initialize()
28 }
29
30 getIdentifier () {
31 return 'FollowersListComponent'
32 }
33
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($localize`${handle} accepted in instance followers`)
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 = $localize`Do you really want to reject this follower?`
53 const res = await this.confirmService.confirm(message, $localize`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($localize`${handle} rejected from instance followers`)
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 = $localize`Do you really want to delete this follower?`
74 const res = await this.confirmService.confirm(message, $localize`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($localize`${handle} removed from instance followers`)
82
83 this.loadData()
84 },
85
86 err => this.notifier.error(err.message)
87 )
88 }
89
90 protected loadData () {
91 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
92 .subscribe(
93 resultList => {
94 this.followers = resultList.data
95 this.totalRecords = resultList.total
96 },
97
98 err => this.notifier.error(err.message)
99 )
100 }
101 }