]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-moderation/video-block.component.ts
Continue user mute in ban modal PR
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / video-block.component.ts
1 import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
4 import { Video } from '@app/shared/shared-main'
5 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
6 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
7 import { VIDEO_BLOCK_REASON_VALIDATOR } from '../form-validators/video-block-validators'
8 import { VideoBlockService } from './video-block.service'
9
10 @Component({
11 selector: 'my-video-block',
12 templateUrl: './video-block.component.html',
13 styleUrls: [ './video-block.component.scss' ]
14 })
15 export class VideoBlockComponent extends FormReactive implements OnInit {
16 @ViewChild('modal', { static: true }) modal: NgbModal
17
18 @Output() videoBlocked = new EventEmitter()
19
20 videos: Video[]
21
22 error: string = null
23
24 private openedModal: NgbModalRef
25
26 constructor (
27 protected formValidatorService: FormValidatorService,
28 private modalService: NgbModal,
29 private videoBlocklistService: VideoBlockService,
30 private notifier: Notifier
31 ) {
32 super()
33 }
34
35 ngOnInit () {
36 const defaultValues = { unfederate: 'true' }
37
38 this.buildForm({
39 reason: VIDEO_BLOCK_REASON_VALIDATOR,
40 unfederate: null
41 }, defaultValues)
42 }
43
44 isMultiple () {
45 return this.videos.length > 1
46 }
47
48 getSingleVideo () {
49 return this.videos[0]
50 }
51
52 hasLive () {
53 return this.videos.some(v => v.isLive)
54 }
55
56 hasLocal () {
57 return this.videos.some(v => v.isLocal)
58 }
59
60 show (videos: Video[]) {
61 this.videos = videos
62
63 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
64 }
65
66 hide () {
67 this.openedModal.close()
68 this.openedModal = null
69 }
70
71 block () {
72 const options = this.videos.map(v => ({
73 videoId: v.id,
74 reason: this.form.value['reason'] || undefined,
75 unfederate: v.isLocal
76 ? this.form.value['unfederate']
77 : undefined
78 }))
79
80 this.videoBlocklistService.blockVideo(options)
81 .subscribe({
82 next: () => {
83 const message = this.isMultiple
84 ? $localize`Blocked ${this.videos.length} videos.`
85 : $localize`Blocked ${this.getSingleVideo().name}`
86
87 this.notifier.success(message)
88 this.hide()
89
90 for (const o of options) {
91 const video = this.videos.find(v => v.id === o.videoId)
92
93 video.blacklisted = true
94 video.blacklistedReason = o.reason
95 }
96
97 this.videoBlocked.emit()
98 },
99
100 error: err => this.notifier.error(err.message)
101 })
102 }
103 }