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