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