]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/follows/following-list/following-list.component.ts
Refactor follow/mute as modals in admin, add actions in abuse list
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / following-list / following-list.component.ts
1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { SortMeta } from 'primeng/api'
4 import { ActorFollow } from '../../../../../../shared/models/actors/follow.model'
5 import { ConfirmService } from '../../../core/confirm/confirm.service'
6 import { RestPagination, RestTable } from '../../../shared'
7 import { FollowService } from '@app/shared/instance/follow.service'
8 import { I18n } from '@ngx-translate/i18n-polyfill'
9 import { BatchDomainsModalComponent } from '@app/+admin/config/shared/batch-domains-modal.component'
10
11 @Component({
12 selector: 'my-followers-list',
13 templateUrl: './following-list.component.html',
14 styleUrls: [ './following-list.component.scss' ]
15 })
16 export class FollowingListComponent extends RestTable implements OnInit {
17 @ViewChild('batchDomainsModal') batchDomainsModal: BatchDomainsModalComponent
18
19 following: ActorFollow[] = []
20 totalRecords = 0
21 rowsPerPage = 10
22 sort: SortMeta = { field: 'createdAt', order: -1 }
23 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
24
25 constructor (
26 private notifier: Notifier,
27 private confirmService: ConfirmService,
28 private followService: FollowService,
29 private i18n: I18n
30 ) {
31 super()
32 }
33
34 ngOnInit () {
35 this.initialize()
36 }
37
38 getIdentifier () {
39 return 'FollowingListComponent'
40 }
41
42 addDomainsToFollow () {
43 this.batchDomainsModal.openModal()
44 }
45
46 async addFollowing (hosts: string[]) {
47 this.followService.follow(hosts).subscribe(
48 () => {
49 this.notifier.success(this.i18n('Follow request(s) sent!'))
50 this.loadData()
51 },
52
53 err => this.notifier.error(err.message)
54 )
55 }
56
57 async removeFollowing (follow: ActorFollow) {
58 const res = await this.confirmService.confirm(
59 this.i18n('Do you really want to unfollow {{host}}?', { host: follow.following.host }),
60 this.i18n('Unfollow')
61 )
62 if (res === false) return
63
64 this.followService.unfollow(follow).subscribe(
65 () => {
66 this.notifier.success(this.i18n('You are not following {{host}} anymore.', { host: follow.following.host }))
67 this.loadData()
68 },
69
70 err => this.notifier.error(err.message)
71 )
72 }
73
74 protected loadData () {
75 this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
76 .subscribe(
77 resultList => {
78 this.following = resultList.data
79 this.totalRecords = resultList.total
80 },
81
82 err => this.notifier.error(err.message)
83 )
84 }
85 }