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

155 lines
5.1 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 } from '@angular/core'
import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
2023-06-06 14:32:47 +02:00
import { formatICU } from '@app/helpers'
import { AdvancedInputFilter } from '@app/shared/shared-forms'
2020-06-23 14:10:17 +02:00
import { InstanceFollowService } from '@app/shared/shared-instance'
2022-07-27 13:44:40 +02:00
import { DropdownAction } from '@app/shared/shared-main'
import { ActorFollow } from '@peertube/peertube-models'
@Component({
selector: 'my-followers-list',
templateUrl: './followers-list.component.html',
2021-10-29 11:33:28 +02:00
styleUrls: [ './followers-list.component.scss' ]
})
export class FollowersListComponent extends RestTable <ActorFollow> implements OnInit {
2018-09-11 16:27:07 +02:00
followers: ActorFollow[] = []
totalRecords = 0
sort: SortMeta = { field: 'createdAt', order: -1 }
pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
2022-07-27 13:44:40 +02:00
searchFilters: AdvancedInputFilter[] = []
bulkActions: DropdownAction<ActorFollow[]>[] = []
constructor (
private confirmService: ConfirmService,
private notifier: Notifier,
2020-06-23 14:10:17 +02:00
private followService: InstanceFollowService
) {
super()
}
2018-02-23 14:36:16 +01:00
ngOnInit () {
2018-10-08 15:51:38 +02:00
this.initialize()
2022-07-27 13:44:40 +02:00
this.searchFilters = this.followService.buildFollowsListFilters()
this.bulkActions = [
2022-07-27 13:44:40 +02:00
{
label: $localize`Reject`,
handler: follows => this.rejectFollower(follows),
isDisplayed: follows => follows.every(f => f.state !== 'rejected')
},
{
label: $localize`Accept`,
handler: follows => this.acceptFollower(follows),
isDisplayed: follows => follows.every(f => f.state !== 'accepted')
},
{
label: $localize`Delete`,
handler: follows => this.deleteFollowers(follows),
isDisplayed: follows => follows.every(f => f.state === 'rejected')
}
]
2018-02-23 14:36:16 +01:00
}
2020-04-08 10:49:26 +02:00
getIdentifier () {
return 'FollowersListComponent'
}
2022-07-27 13:44:40 +02:00
acceptFollower (follows: ActorFollow[]) {
this.followService.acceptFollower(follows)
2021-08-17 11:27:47 +02:00
.subscribe({
next: () => {
2022-07-27 13:44:40 +02:00
// eslint-disable-next-line max-len
2023-06-06 14:32:47 +02:00
const message = formatICU(
$localize`Accepted {count, plural, =1 {{followerName} follow request} other {{count} follow requests}}`,
{ count: follows.length, followerName: this.buildFollowerName(follows[0]) }
2022-07-27 13:44:40 +02:00
)
this.notifier.success(message)
this.reloadData()
},
2022-07-27 13:44:40 +02:00
error: err => this.notifier.error(err.message)
2021-08-17 11:27:47 +02:00
})
}
2022-07-27 13:44:40 +02:00
async rejectFollower (follows: ActorFollow[]) {
// eslint-disable-next-line max-len
2023-06-06 14:32:47 +02:00
const message = formatICU(
$localize`Do you really want to reject {count, plural, =1 {{followerName} follow request?} other {{count} follow requests?}}`,
{ count: follows.length, followerName: this.buildFollowerName(follows[0]) }
2022-07-27 13:44:40 +02:00
)
const res = await this.confirmService.confirm(message, $localize`Reject`)
if (res === false) return
2022-07-27 13:44:40 +02:00
this.followService.rejectFollower(follows)
2021-08-17 11:27:47 +02:00
.subscribe({
next: () => {
2022-07-27 13:44:40 +02:00
// eslint-disable-next-line max-len
2023-06-06 14:32:47 +02:00
const message = formatICU(
$localize`Rejected {count, plural, =1 {{followerName} follow request} other {{count} follow requests}}`,
{ count: follows.length, followerName: this.buildFollowerName(follows[0]) }
2022-07-27 13:44:40 +02:00
)
this.notifier.success(message)
2021-05-03 14:33:34 +02:00
this.reloadData()
},
2022-07-27 13:44:40 +02:00
error: err => this.notifier.error(err.message)
2021-08-17 11:27:47 +02:00
})
}
2022-07-27 13:44:40 +02:00
async deleteFollowers (follows: ActorFollow[]) {
const icuParams = { count: follows.length, followerName: this.buildFollowerName(follows[0]) }
2022-07-27 13:44:40 +02:00
let message = $localize`Deleted followers will be able to send again a follow request.`
message += '<br /><br />'
// eslint-disable-next-line max-len
2023-06-06 14:32:47 +02:00
message += formatICU(
$localize`Do you really want to delete {count, plural, =1 {{followerName} follow request?} other {{count} follow requests?}}`,
icuParams
2022-07-27 13:44:40 +02:00
)
const res = await this.confirmService.confirm(message, $localize`Delete`)
if (res === false) return
2022-07-27 13:44:40 +02:00
this.followService.removeFollower(follows)
2021-08-17 11:27:47 +02:00
.subscribe({
next: () => {
2022-07-27 13:44:40 +02:00
// eslint-disable-next-line max-len
2023-06-06 14:32:47 +02:00
const message = formatICU(
$localize`Removed {count, plural, =1 {{followerName} follow request} other {{count} follow requests}}`,
icuParams
2022-07-27 13:44:40 +02:00
)
this.notifier.success(message)
2021-05-03 14:33:34 +02:00
this.reloadData()
},
2021-08-17 11:27:47 +02:00
error: err => this.notifier.error(err.message)
})
}
2022-07-27 13:44:40 +02:00
buildFollowerName (follow: ActorFollow) {
return follow.follower.name + '@' + follow.follower.host
}
2023-01-20 15:06:08 +01:00
protected reloadDataInternal () {
this.followService.getFollowers({ pagination: this.pagination, sort: this.sort, search: this.search })
2021-08-17 11:27:47 +02:00
.subscribe({
next: resultList => {
this.followers = resultList.data
this.totalRecords = resultList.total
},
2021-08-17 11:27:47 +02:00
error: err => this.notifier.error(err.message)
})
}
}