]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/follows/followers-list/followers-list.component.ts
Refactor follow/mute as modals in admin, add actions in abuse list
[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: [ './followers-list.component.scss' ]
13 })
14 export class FollowersListComponent extends RestTable implements OnInit {
15 followers: ActorFollow[] = []
16 totalRecords = 0
17 rowsPerPage = 10
18 sort: SortMeta = { field: 'createdAt', order: -1 }
19 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
20
21 constructor (
22 private confirmService: ConfirmService,
23 private notifier: Notifier,
24 private i18n: I18n,
25 private followService: FollowService
26 ) {
27 super()
28 }
29
30 ngOnInit () {
31 this.initialize()
32 }
33
34 getIdentifier () {
35 return 'FollowersListComponent'
36 }
37
38 acceptFollower (follow: ActorFollow) {
39 follow.state = 'accepted'
40
41 this.followService.acceptFollower(follow)
42 .subscribe(
43 () => {
44 const handle = follow.follower.name + '@' + follow.follower.host
45 this.notifier.success(this.i18n('{{handle}} accepted in instance followers', { handle }))
46 },
47
48 err => {
49 follow.state = 'pending'
50 this.notifier.error(err.message)
51 }
52 )
53 }
54
55 async rejectFollower (follow: ActorFollow) {
56 const message = this.i18n('Do you really want to reject this follower?')
57 const res = await this.confirmService.confirm(message, this.i18n('Reject'))
58 if (res === false) return
59
60 this.followService.rejectFollower(follow)
61 .subscribe(
62 () => {
63 const handle = follow.follower.name + '@' + follow.follower.host
64 this.notifier.success(this.i18n('{{handle}} rejected from instance followers', { handle }))
65
66 this.loadData()
67 },
68
69 err => {
70 follow.state = 'pending'
71 this.notifier.error(err.message)
72 }
73 )
74 }
75
76 async deleteFollower (follow: ActorFollow) {
77 const message = this.i18n('Do you really want to delete this follower?')
78 const res = await this.confirmService.confirm(message, this.i18n('Delete'))
79 if (res === false) return
80
81 this.followService.removeFollower(follow)
82 .subscribe(
83 () => {
84 const handle = follow.follower.name + '@' + follow.follower.host
85 this.notifier.success(this.i18n('{{handle}} removed from instance followers', { handle }))
86
87 this.loadData()
88 },
89
90 err => this.notifier.error(err.message)
91 )
92 }
93
94 protected loadData () {
95 this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
96 .subscribe(
97 resultList => {
98 this.followers = resultList.data
99 this.totalRecords = resultList.total
100 },
101
102 err => this.notifier.error(err.message)
103 )
104 }
105 }