]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/follows/following-list/following-list.component.ts
Add ability for instances to follow any actor
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / following-list / following-list.component.ts
1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit, ViewChild } from '@angular/core'
3 import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
4 import { InstanceFollowService } from '@app/shared/shared-instance'
5 import { BatchDomainsModalComponent } from '@app/shared/shared-moderation'
6 import { ActorFollow } from '@shared/models'
7 import { FollowModalComponent } from './follow-modal.component'
8
9 @Component({
10 templateUrl: './following-list.component.html',
11 styleUrls: [ '../follows.component.scss', './following-list.component.scss' ]
12 })
13 export class FollowingListComponent extends RestTable implements OnInit {
14 @ViewChild('followModal') followModal: FollowModalComponent
15
16 following: ActorFollow[] = []
17 totalRecords = 0
18 sort: SortMeta = { field: 'createdAt', order: -1 }
19 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
20
21 constructor (
22 private notifier: Notifier,
23 private confirmService: ConfirmService,
24 private followService: InstanceFollowService
25 ) {
26 super()
27 }
28
29 ngOnInit () {
30 this.initialize()
31 }
32
33 getIdentifier () {
34 return 'FollowingListComponent'
35 }
36
37 openFollowModal () {
38 this.followModal.openModal()
39 }
40
41 isInstanceFollowing (follow: ActorFollow) {
42 return follow.following.name === 'peertube'
43 }
44
45 async removeFollowing (follow: ActorFollow) {
46 const res = await this.confirmService.confirm(
47 $localize`Do you really want to unfollow ${follow.following.host}?`,
48 $localize`Unfollow`
49 )
50 if (res === false) return
51
52 this.followService.unfollow(follow).subscribe(
53 () => {
54 this.notifier.success($localize`You are not following ${follow.following.host} anymore.`)
55 this.reloadData()
56 },
57
58 err => this.notifier.error(err.message)
59 )
60 }
61
62 protected reloadData () {
63 this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
64 .subscribe(
65 resultList => {
66 this.following = resultList.data
67 this.totalRecords = resultList.total
68 },
69
70 err => this.notifier.error(err.message)
71 )
72 }
73 }