PeerTube/client/src/app/+admin/overview/comments/video-comment-list.componen...

193 lines
5.6 KiB
TypeScript
Raw Normal View History

2020-11-13 16:38:23 +01:00
import { SortMeta } from 'primeng/api'
2021-08-17 11:27:47 +02:00
import { Component, OnInit } from '@angular/core'
2020-11-20 13:55:33 +01:00
import { ActivatedRoute, Router } from '@angular/router'
2020-11-16 11:55:17 +01:00
import { AuthService, ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core'
import { AdvancedInputFilter } from '@app/shared/shared-forms'
2020-11-16 11:55:17 +01:00
import { DropdownAction } from '@app/shared/shared-main'
import { BulkService } from '@app/shared/shared-moderation'
2020-11-13 16:38:23 +01:00
import { VideoCommentAdmin, VideoCommentService } from '@app/shared/shared-video-comment'
import { FeedFormat, UserRight } from '@peertube/peertube-models'
2023-06-06 14:32:47 +02:00
import { formatICU } from '@app/helpers'
2020-11-13 16:38:23 +01:00
@Component({
selector: 'my-video-comment-list',
templateUrl: './video-comment-list.component.html',
2020-11-16 11:55:17 +01:00
styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-comment-list.component.scss' ]
2020-11-13 16:38:23 +01:00
})
export class VideoCommentListComponent extends RestTable <VideoCommentAdmin> implements OnInit {
2020-11-13 16:38:23 +01:00
comments: VideoCommentAdmin[]
totalRecords = 0
sort: SortMeta = { field: 'createdAt', order: -1 }
pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
videoCommentActions: DropdownAction<VideoCommentAdmin>[][] = []
2020-11-16 11:55:17 +01:00
syndicationItems = [
{
format: FeedFormat.RSS,
label: 'media rss 2.0',
url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.RSS.toLowerCase()
},
{
format: FeedFormat.ATOM,
label: 'atom 1.0',
url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.ATOM.toLowerCase()
},
{
format: FeedFormat.JSON,
label: 'json 1.0',
url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.JSON.toLowerCase()
}
]
bulkActions: DropdownAction<VideoCommentAdmin[]>[] = []
2020-11-20 13:55:33 +01:00
inputFilters: AdvancedInputFilter[] = [
{
title: $localize`Advanced filters`,
children: [
{
2021-11-03 14:23:55 +01:00
value: 'local:true',
label: $localize`Local comments`
},
{
2021-11-03 14:23:55 +01:00
value: 'local:false',
label: $localize`Remote comments`
},
{
value: 'localVideo:true',
label: $localize`Comments on local videos`
}
]
}
]
2020-11-16 11:55:17 +01:00
get authUser () {
return this.auth.getUser()
}
2020-11-13 16:38:23 +01:00
constructor (
2020-11-16 14:47:05 +01:00
protected router: Router,
protected route: ActivatedRoute,
2020-11-16 11:55:17 +01:00
private auth: AuthService,
2020-11-13 16:38:23 +01:00
private notifier: Notifier,
private confirmService: ConfirmService,
private videoCommentService: VideoCommentService,
private markdownRenderer: MarkdownService,
2020-11-16 11:55:17 +01:00
private bulkService: BulkService
2021-08-17 14:42:53 +02:00
) {
2020-11-13 16:38:23 +01:00
super()
this.videoCommentActions = [
[
2020-11-16 11:55:17 +01:00
{
label: $localize`Delete this comment`,
handler: comment => this.deleteComment(comment),
isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
},
2020-11-13 16:38:23 +01:00
2020-11-16 11:55:17 +01:00
{
label: $localize`Delete all comments of this account`,
description: $localize`Comments are deleted after a few minutes`,
handler: comment => this.deleteUserComments(comment),
isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
}
2020-11-13 16:38:23 +01:00
]
]
}
ngOnInit () {
this.initialize()
2020-11-20 13:55:33 +01:00
this.bulkActions = [
2020-11-20 13:55:33 +01:00
{
label: $localize`Delete`,
handler: comments => this.removeComments(comments),
isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT),
iconName: 'delete'
}
]
2020-11-13 16:38:23 +01:00
}
getIdentifier () {
return 'VideoCommentListComponent'
}
toHtml (text: string) {
return this.markdownRenderer.textMarkdownToHTML({ markdown: text, withHtml: true, withEmoji: true })
2020-11-13 16:38:23 +01:00
}
2023-01-20 15:06:08 +01:00
protected reloadDataInternal () {
2020-11-13 16:38:23 +01:00
this.videoCommentService.getAdminVideoComments({
pagination: this.pagination,
sort: this.sort,
search: this.search
2021-08-17 11:27:47 +02:00
}).subscribe({
next: async resultList => {
this.totalRecords = resultList.total
2020-11-13 16:38:23 +01:00
2021-08-17 11:27:47 +02:00
this.comments = []
2020-11-13 16:38:23 +01:00
2021-08-17 11:27:47 +02:00
for (const c of resultList.data) {
this.comments.push(
new VideoCommentAdmin(c, await this.toHtml(c.text))
)
}
},
2020-11-13 16:38:23 +01:00
2021-08-17 11:27:47 +02:00
error: err => this.notifier.error(err.message)
})
2020-11-13 16:38:23 +01:00
}
2020-11-16 11:55:17 +01:00
2021-08-25 16:14:11 +02:00
private removeComments (comments: VideoCommentAdmin[]) {
2020-11-20 13:55:33 +01:00
const commentArgs = comments.map(c => ({ videoId: c.video.id, commentId: c.id }))
2021-08-17 11:27:47 +02:00
this.videoCommentService.deleteVideoComments(commentArgs)
.subscribe({
next: () => {
2022-05-24 16:29:01 +02:00
this.notifier.success(
2023-06-06 14:32:47 +02:00
formatICU(
$localize`{count, plural, =1 {1 comment deleted.} other {{count} comments deleted.}}`,
{ count: commentArgs.length }
2022-05-24 16:29:01 +02:00
)
)
2021-08-17 11:27:47 +02:00
this.reloadData()
},
2020-11-20 13:55:33 +01:00
2021-08-17 11:27:47 +02:00
error: err => this.notifier.error(err.message),
2020-11-20 13:55:33 +01:00
complete: () => this.selectedRows = []
2021-08-17 11:27:47 +02:00
})
2020-11-20 13:55:33 +01:00
}
2020-11-16 11:55:17 +01:00
private deleteComment (comment: VideoCommentAdmin) {
this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
2021-08-17 11:27:47 +02:00
.subscribe({
next: () => this.reloadData(),
2020-11-16 11:55:17 +01:00
2021-08-17 11:27:47 +02:00
error: err => this.notifier.error(err.message)
})
2020-11-16 11:55:17 +01:00
}
private async deleteUserComments (comment: VideoCommentAdmin) {
const message = $localize`Do you really want to delete all comments of ${comment.by}?`
const res = await this.confirmService.confirm(message, $localize`Delete`)
if (res === false) return
const options = {
accountName: comment.by,
scope: 'instance' as 'instance'
}
this.bulkService.removeCommentsOf(options)
2021-08-17 11:27:47 +02:00
.subscribe({
next: () => {
2020-11-16 11:55:17 +01:00
this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
},
2021-08-17 11:27:47 +02:00
error: err => this.notifier.error(err.message)
})
2020-11-16 11:55:17 +01:00
}
2020-11-13 16:38:23 +01:00
}