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