]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts
Use travis.com badge now
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / moderation / video-abuse-list / video-abuse-list.component.ts
CommitLineData
efc9e845 1import { Component, OnInit, ViewChild } from '@angular/core'
614d1ae9 2import { Account } from '../../../shared/account/account.model'
f8b2c1b4 3import { Notifier } from '@app/core'
f77eb73b 4import { SortMeta } from 'primeng/api'
efc9e845 5import { VideoAbuse, VideoAbuseState } from '../../../../../../shared'
19a3b914 6import { RestPagination, RestTable, VideoAbuseService } from '../../../shared'
b1d40cff 7import { I18n } from '@ngx-translate/i18n-polyfill'
614d1ae9
C
8import { DropdownAction } from '../../../shared/buttons/action-dropdown.component'
9import { ConfirmService } from '../../../core/index'
efc9e845 10import { ModerationCommentModalComponent } from './moderation-comment-modal.component'
614d1ae9 11import { Video } from '../../../shared/video/video.model'
1506307f 12import { MarkdownService } from '@app/shared/renderer'
d6af8146
RK
13import { Actor } from '@app/shared/actor/actor.model'
14import { buildVideoLink, buildVideoEmbed } from 'src/assets/player/utils'
15import { getAbsoluteAPIUrl } from '@app/shared/misc/utils'
16import { DomSanitizer } from '@angular/platform-browser'
19a3b914 17
11ac88de 18@Component({
df98563e 19 selector: 'my-video-abuse-list',
f595d394 20 templateUrl: './video-abuse-list.component.html',
83b5fe9c 21 styleUrls: [ '../moderation.component.scss']
11ac88de 22})
d592e0a9 23export class VideoAbuseListComponent extends RestTable implements OnInit {
f36da21e 24 @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent
efc9e845 25
41d71344 26 videoAbuses: (VideoAbuse & { moderationCommentHtml?: string, reasonHtml?: string })[] = []
d592e0a9 27 totalRecords = 0
d5050d1e 28 rowsPerPage = 10
ab998f7b 29 sort: SortMeta = { field: 'createdAt', order: 1 }
d592e0a9 30 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
11ac88de 31
efc9e845
C
32 videoAbuseActions: DropdownAction<VideoAbuse>[] = []
33
df98563e 34 constructor (
f8b2c1b4 35 private notifier: Notifier,
b1d40cff 36 private videoAbuseService: VideoAbuseService,
efc9e845 37 private confirmService: ConfirmService,
1506307f 38 private i18n: I18n,
d6af8146
RK
39 private markdownRenderer: MarkdownService,
40 private sanitizer: DomSanitizer
28798b5d 41 ) {
d592e0a9 42 super()
efc9e845
C
43
44 this.videoAbuseActions = [
45 {
5aa4a3dd 46 label: this.i18n('Delete this report'),
efc9e845
C
47 handler: videoAbuse => this.removeVideoAbuse(videoAbuse)
48 },
49 {
d6af8146
RK
50 label: this.i18n('Add note'),
51 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
52 isDisplayed: videoAbuse => !videoAbuse.moderationComment
53 },
54 {
55 label: this.i18n('Update note'),
56 handler: videoAbuse => this.openModerationCommentModal(videoAbuse),
57 isDisplayed: videoAbuse => !!videoAbuse.moderationComment
efc9e845
C
58 },
59 {
60 label: this.i18n('Mark as accepted'),
61 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED),
62 isDisplayed: videoAbuse => !this.isVideoAbuseAccepted(videoAbuse)
63 },
64 {
65 label: this.i18n('Mark as rejected'),
66 handler: videoAbuse => this.updateVideoAbuseState(videoAbuse, VideoAbuseState.REJECTED),
67 isDisplayed: videoAbuse => !this.isVideoAbuseRejected(videoAbuse)
68 }
69 ]
d592e0a9
C
70 }
71
72 ngOnInit () {
24b9417c 73 this.initialize()
df98563e 74 }
11ac88de 75
8e11a1b3
C
76 getIdentifier () {
77 return 'VideoAbuseListComponent'
78 }
79
efc9e845
C
80 openModerationCommentModal (videoAbuse: VideoAbuse) {
81 this.moderationCommentModal.openModal(videoAbuse)
82 }
83
84 onModerationCommentUpdated () {
85 this.loadData()
86 }
87
19a3b914
C
88 createByString (account: Account) {
89 return Account.CREATE_BY_STRING(account.name, account.host)
d592e0a9
C
90 }
91
efc9e845
C
92 isVideoAbuseAccepted (videoAbuse: VideoAbuse) {
93 return videoAbuse.state.id === VideoAbuseState.ACCEPTED
94 }
95
96 isVideoAbuseRejected (videoAbuse: VideoAbuse) {
97 return videoAbuse.state.id === VideoAbuseState.REJECTED
98 }
99
191764f3
C
100 getVideoUrl (videoAbuse: VideoAbuse) {
101 return Video.buildClientUrl(videoAbuse.video.uuid)
102 }
103
d6af8146
RK
104 getVideoEmbed (videoAbuse: VideoAbuse) {
105 const absoluteAPIUrl = 'http://localhost:9000' || getAbsoluteAPIUrl()
106 const embedUrl = buildVideoLink({
107 baseUrl: absoluteAPIUrl + '/videos/embed/' + videoAbuse.video.uuid,
108 warningTitle: false
109 })
110 return buildVideoEmbed(embedUrl)
111 }
112
113 switchToDefaultAvatar ($event: Event) {
114 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
115 }
116
efc9e845 117 async removeVideoAbuse (videoAbuse: VideoAbuse) {
198d764f 118 const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this abuse report?'), this.i18n('Delete'))
efc9e845
C
119 if (res === false) return
120
121 this.videoAbuseService.removeVideoAbuse(videoAbuse).subscribe(
122 () => {
f8b2c1b4 123 this.notifier.success(this.i18n('Abuse deleted.'))
efc9e845
C
124 this.loadData()
125 },
126
f8b2c1b4 127 err => this.notifier.error(err.message)
efc9e845
C
128 )
129 }
130
131 updateVideoAbuseState (videoAbuse: VideoAbuse, state: VideoAbuseState) {
132 this.videoAbuseService.updateVideoAbuse(videoAbuse, { state })
133 .subscribe(
134 () => this.loadData(),
135
f8b2c1b4 136 err => this.notifier.error(err.message)
efc9e845
C
137 )
138
139 }
140
d592e0a9
C
141 protected loadData () {
142 return this.videoAbuseService.getVideoAbuses(this.pagination, this.sort)
143 .subscribe(
41d71344 144 async resultList => {
d592e0a9 145 this.totalRecords = resultList.total
41d71344
C
146
147 this.videoAbuses = resultList.data
148
149 for (const abuse of this.videoAbuses) {
150 Object.assign(abuse, {
151 reasonHtml: await this.toHtml(abuse.reason),
d6af8146
RK
152 moderationCommentHtml: await this.toHtml(abuse.moderationComment),
153 embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse))
41d71344
C
154 })
155 }
156
d592e0a9
C
157 },
158
f8b2c1b4 159 err => this.notifier.error(err.message)
d592e0a9 160 )
11ac88de 161 }
41d71344
C
162
163 private toHtml (text: string) {
164 return this.markdownRenderer.textMarkdownToHTML(text)
165 }
11ac88de 166}