]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/follows/following-list/following-list.component.ts
383f66ffde6baf3f1b22c51eff04841a6398525f
[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 { ActorFollow } from '@shared/models'
6 import { FollowModalComponent } from './follow-modal.component'
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('followModal') followModal: FollowModalComponent
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 openFollowModal () {
37 this.followModal.openModal()
38 }
39
40 isInstanceFollowing (follow: ActorFollow) {
41 return follow.following.name === 'peertube'
42 }
43
44 async removeFollowing (follow: ActorFollow) {
45 const res = await this.confirmService.confirm(
46 $localize`Do you really want to unfollow ${follow.following.host}?`,
47 $localize`Unfollow`
48 )
49 if (res === false) return
50
51 this.followService.unfollow(follow)
52 .subscribe({
53 next: () => {
54 this.notifier.success($localize`You are not following ${follow.following.host} anymore.`)
55 this.reloadData()
56 },
57
58 error: 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 next: resultList => {
66 this.following = resultList.data
67 this.totalRecords = resultList.total
68 },
69
70 error: err => this.notifier.error(err.message)
71 })
72 }
73 }