PeerTube/client/src/app/+admin/follows/following-list/following-list.component.ts

84 lines
2.4 KiB
TypeScript
Raw Normal View History

2019-07-25 10:44:21 +02:00
import { SortMeta } from 'primeng/api'
2020-06-23 14:10:17 +02:00
import { Component, OnInit, ViewChild } from '@angular/core'
import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
import { InstanceFollowService } from '@app/shared/shared-instance'
import { BatchDomainsModalComponent } from '@app/shared/shared-moderation'
import { ActorFollow } from '@shared/models'
@Component({
2018-09-11 16:27:07 +02:00
templateUrl: './following-list.component.html',
2020-04-19 20:26:25 +02:00
styleUrls: [ '../follows.component.scss', './following-list.component.scss' ]
})
2018-02-23 14:36:16 +01:00
export class FollowingListComponent extends RestTable implements OnInit {
@ViewChild('batchDomainsModal') batchDomainsModal: BatchDomainsModalComponent
2018-09-11 16:27:07 +02:00
following: ActorFollow[] = []
totalRecords = 0
sort: SortMeta = { field: 'createdAt', order: -1 }
pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
constructor (
private notifier: Notifier,
2017-11-20 11:19:23 +01:00
private confirmService: ConfirmService,
private followService: InstanceFollowService
) {
super()
}
2018-02-23 14:36:16 +01:00
ngOnInit () {
2018-10-08 15:51:38 +02:00
this.initialize()
2018-02-23 14:36:16 +01:00
}
2020-04-08 10:49:26 +02:00
getIdentifier () {
return 'FollowingListComponent'
}
addDomainsToFollow () {
this.batchDomainsModal.openModal()
}
httpEnabled () {
return window.location.protocol === 'https:'
}
async addFollowing (hosts: string[]) {
this.followService.follow(hosts).subscribe(
() => {
this.notifier.success($localize`Follow request(s) sent!`)
2021-05-03 14:33:34 +02:00
this.reloadData()
},
err => this.notifier.error(err.message)
)
}
2018-09-11 16:27:07 +02:00
async removeFollowing (follow: ActorFollow) {
2018-06-04 16:21:17 +02:00
const res = await this.confirmService.confirm(
$localize`Do you really want to unfollow ${follow.following.host}?`,
$localize`Unfollow`
2018-06-04 16:21:17 +02:00
)
if (res === false) return
2017-11-20 11:19:23 +01:00
this.followService.unfollow(follow).subscribe(
() => {
this.notifier.success($localize`You are not following ${follow.following.host} anymore.`)
2021-05-03 14:33:34 +02:00
this.reloadData()
},
2017-11-20 11:19:23 +01:00
err => this.notifier.error(err.message)
2017-11-20 11:19:23 +01:00
)
}
2021-05-03 14:33:34 +02:00
protected reloadData () {
this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
.subscribe(
resultList => {
this.following = resultList.data
this.totalRecords = resultList.total
},
err => this.notifier.error(err.message)
)
}
}