aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-16 11:55:17 +0100
committerChocobozzz <me@florianbigard.com>2020-11-16 13:48:58 +0100
commitf1273314593a4a7dc7ec9594ce0c6c3ae8f62b34 (patch)
treecf1f3949e64a24a820833950d7b2bbf9ccd40013 /client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts
parent0f8d00e3144060270d7fe603865fccaf18649c47 (diff)
downloadPeerTube-f1273314593a4a7dc7ec9594ce0c6c3ae8f62b34.tar.gz
PeerTube-f1273314593a4a7dc7ec9594ce0c6c3ae8f62b34.tar.zst
PeerTube-f1273314593a4a7dc7ec9594ce0c6c3ae8f62b34.zip
Add admin view to manage comments
Diffstat (limited to 'client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts')
-rw-r--r--client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts86
1 files changed, 72 insertions, 14 deletions
diff --git a/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts b/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts
index fdd5ec76e..d26047125 100644
--- a/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts
+++ b/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts
@@ -1,16 +1,17 @@
1import { SortMeta } from 'primeng/api' 1import { SortMeta } from 'primeng/api'
2import { filter } from 'rxjs/operators' 2import { filter } from 'rxjs/operators'
3import { AfterViewInit, Component, OnInit } from '@angular/core' 3import { AfterViewInit, Component, OnInit } from '@angular/core'
4import { DomSanitizer } from '@angular/platform-browser'
5import { ActivatedRoute, Params, Router } from '@angular/router' 4import { ActivatedRoute, Params, Router } from '@angular/router'
6import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable, ServerService } from '@app/core' 5import { AuthService, ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core'
7import { DropdownAction, VideoService } from '@app/shared/shared-main' 6import { DropdownAction } from '@app/shared/shared-main'
7import { BulkService } from '@app/shared/shared-moderation'
8import { VideoCommentAdmin, VideoCommentService } from '@app/shared/shared-video-comment' 8import { VideoCommentAdmin, VideoCommentService } from '@app/shared/shared-video-comment'
9import { FeedFormat, UserRight } from '@shared/models'
9 10
10@Component({ 11@Component({
11 selector: 'my-video-comment-list', 12 selector: 'my-video-comment-list',
12 templateUrl: './video-comment-list.component.html', 13 templateUrl: './video-comment-list.component.html',
13 styleUrls: [ './video-comment-list.component.scss' ] 14 styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-comment-list.component.scss' ]
14}) 15})
15export class VideoCommentListComponent extends RestTable implements OnInit, AfterViewInit { 16export class VideoCommentListComponent extends RestTable implements OnInit, AfterViewInit {
16 comments: VideoCommentAdmin[] 17 comments: VideoCommentAdmin[]
@@ -20,26 +21,54 @@ export class VideoCommentListComponent extends RestTable implements OnInit, Afte
20 21
21 videoCommentActions: DropdownAction<VideoCommentAdmin>[][] = [] 22 videoCommentActions: DropdownAction<VideoCommentAdmin>[][] = []
22 23
24 syndicationItems = [
25 {
26 format: FeedFormat.RSS,
27 label: 'media rss 2.0',
28 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.RSS.toLowerCase()
29 },
30 {
31 format: FeedFormat.ATOM,
32 label: 'atom 1.0',
33 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.ATOM.toLowerCase()
34 },
35 {
36 format: FeedFormat.JSON,
37 label: 'json 1.0',
38 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.JSON.toLowerCase()
39 }
40 ]
41
42 get authUser () {
43 return this.auth.getUser()
44 }
45
23 constructor ( 46 constructor (
47 private auth: AuthService,
24 private notifier: Notifier, 48 private notifier: Notifier,
25 private serverService: ServerService,
26 private confirmService: ConfirmService, 49 private confirmService: ConfirmService,
27 private videoCommentService: VideoCommentService, 50 private videoCommentService: VideoCommentService,
28 private markdownRenderer: MarkdownService, 51 private markdownRenderer: MarkdownService,
29 private sanitizer: DomSanitizer,
30 private videoService: VideoService,
31 private route: ActivatedRoute, 52 private route: ActivatedRoute,
32 private router: Router 53 private router: Router,
54 private bulkService: BulkService
33 ) { 55 ) {
34 super() 56 super()
35 57
36 this.videoCommentActions = [ 58 this.videoCommentActions = [
37 [ 59 [
60 {
61 label: $localize`Delete this comment`,
62 handler: comment => this.deleteComment(comment),
63 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
64 },
38 65
39 // remove this comment, 66 {
40 67 label: $localize`Delete all comments of this account`,
41 // remove all comments of this account 68 description: $localize`Comments are deleted after a few minutes`,
42 69 handler: comment => this.deleteUserComments(comment),
70 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
71 }
43 ] 72 ]
44 ] 73 ]
45 } 74 }
@@ -60,7 +89,7 @@ export class VideoCommentListComponent extends RestTable implements OnInit, Afte
60 if (this.search) this.setTableFilter(this.search) 89 if (this.search) this.setTableFilter(this.search)
61 } 90 }
62 91
63 onSearch (event: Event) { 92 onInputSearch (event: Event) {
64 this.onSearch(event) 93 this.onSearch(event)
65 this.setQueryParams((event.target as HTMLInputElement).value) 94 this.setQueryParams((event.target as HTMLInputElement).value)
66 } 95 }
@@ -84,7 +113,7 @@ export class VideoCommentListComponent extends RestTable implements OnInit, Afte
84 } 113 }
85 114
86 toHtml (text: string) { 115 toHtml (text: string) {
87 return this.markdownRenderer.textMarkdownToHTML(text) 116 return this.markdownRenderer.textMarkdownToHTML(text, true, true)
88 } 117 }
89 118
90 protected loadData () { 119 protected loadData () {
@@ -108,4 +137,33 @@ export class VideoCommentListComponent extends RestTable implements OnInit, Afte
108 err => this.notifier.error(err.message) 137 err => this.notifier.error(err.message)
109 ) 138 )
110 } 139 }
140
141 private deleteComment (comment: VideoCommentAdmin) {
142 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
143 .subscribe(
144 () => this.loadData(),
145
146 err => this.notifier.error(err.message)
147 )
148 }
149
150 private async deleteUserComments (comment: VideoCommentAdmin) {
151 const message = $localize`Do you really want to delete all comments of ${comment.by}?`
152 const res = await this.confirmService.confirm(message, $localize`Delete`)
153 if (res === false) return
154
155 const options = {
156 accountName: comment.by,
157 scope: 'instance' as 'instance'
158 }
159
160 this.bulkService.removeCommentsOf(options)
161 .subscribe(
162 () => {
163 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
164 },
165
166 err => this.notifier.error(err.message)
167 )
168 }
111} 169}