]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
41b15c89 1import { SortMeta } from 'primeng/api'
67ed6552
C
2import { Component, OnInit } from '@angular/core'
3import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
4import { InstanceFollowService } from '@app/shared/shared-instance'
67ed6552 5import { ActorFollow } from '@shared/models'
51548b31
C
6
7@Component({
8 selector: 'my-followers-list',
9 templateUrl: './followers-list.component.html',
d3840613 10 styleUrls: [ '../follows.component.scss', './followers-list.component.scss' ]
51548b31 11})
ab998f7b 12export class FollowersListComponent extends RestTable implements OnInit {
c48e82b5 13 followers: ActorFollow[] = []
51548b31 14 totalRecords = 0
bb152476 15 sort: SortMeta = { field: 'createdAt', order: -1 }
51548b31
C
16 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
17
18 constructor (
0dc64777 19 private confirmService: ConfirmService,
f8b2c1b4 20 private notifier: Notifier,
67ed6552 21 private followService: InstanceFollowService
51548b31
C
22 ) {
23 super()
24 }
25
ab998f7b 26 ngOnInit () {
24b9417c 27 this.initialize()
ab998f7b
C
28 }
29
8e11a1b3
C
30 getIdentifier () {
31 return 'FollowersListComponent'
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
66357162 41 this.notifier.success($localize`${handle} accepted in instance followers`)
0dc64777
C
42 },
43
44 err => {
45 follow.state = 'pending'
46 this.notifier.error(err.message)
47 }
48 )
49 }
50
51 async rejectFollower (follow: ActorFollow) {
66357162
C
52 const message = $localize`Do you really want to reject this follower?`
53 const res = await this.confirmService.confirm(message, $localize`Reject`)
0dc64777
C
54 if (res === false) return
55
56 this.followService.rejectFollower(follow)
57 .subscribe(
58 () => {
59 const handle = follow.follower.name + '@' + follow.follower.host
66357162 60 this.notifier.success($localize`${handle} rejected from instance followers`)
0dc64777
C
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) {
66357162
C
73 const message = $localize`Do you really want to delete this follower?`
74 const res = await this.confirmService.confirm(message, $localize`Delete`)
0dc64777
C
75 if (res === false) return
76
77 this.followService.removeFollower(follow)
78 .subscribe(
79 () => {
80 const handle = follow.follower.name + '@' + follow.follower.host
66357162 81 this.notifier.success($localize`${handle} removed from instance followers`)
0dc64777
C
82
83 this.loadData()
84 },
85
86 err => this.notifier.error(err.message)
87 )
88 }
89
51548b31 90 protected loadData () {
b8f4167f 91 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: 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}