]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/follows/following-list/following-list.component.ts
f34490cc87c9888e7afc326e1f6b43ddea310729
[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
8 @Component({
9 templateUrl: './following-list.component.html',
10 styleUrls: [ '../follows.component.scss', './following-list.component.scss' ]
11 })
12 export class FollowingListComponent extends RestTable implements OnInit {
13 @ViewChild('batchDomainsModal') batchDomainsModal: BatchDomainsModalComponent
14
15 following: ActorFollow[] = []
16 totalRecords = 0
17 sort: SortMeta = { field: 'createdAt', order: -1 }
18 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
19
20 constructor (
21 private notifier: Notifier,
22 private confirmService: ConfirmService,
23 private followService: InstanceFollowService
24 ) {
25 super()
26 }
27
28 ngOnInit () {
29 this.initialize()
30 }
31
32 getIdentifier () {
33 return 'FollowingListComponent'
34 }
35
36 addDomainsToFollow () {
37 this.batchDomainsModal.openModal()
38 }
39
40 httpEnabled () {
41 return window.location.protocol === 'https:'
42 }
43
44 async addFollowing (hosts: string[]) {
45 this.followService.follow(hosts).subscribe(
46 () => {
47 this.notifier.success($localize`Follow request(s) sent!`)
48 this.loadData()
49 },
50
51 err => this.notifier.error(err.message)
52 )
53 }
54
55 async removeFollowing (follow: ActorFollow) {
56 const res = await this.confirmService.confirm(
57 $localize`Do you really want to unfollow ${follow.following.host}?`,
58 $localize`Unfollow`
59 )
60 if (res === false) return
61
62 this.followService.unfollow(follow).subscribe(
63 () => {
64 this.notifier.success($localize`You are not following ${follow.following.host} anymore.`)
65 this.loadData()
66 },
67
68 err => this.notifier.error(err.message)
69 )
70 }
71
72 protected loadData () {
73 this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
74 .subscribe(
75 resultList => {
76 this.following = resultList.data
77 this.totalRecords = resultList.total
78 },
79
80 err => this.notifier.error(err.message)
81 )
82 }
83 }