]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/+video-watch/comment/video-comment.component.ts
Merge branch 'release/v1.2.0'
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / comment / video-comment.component.ts
1 import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'
2 import { UserRight } from '../../../../../../shared/models/users'
3 import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
4 import { AuthService } from '../../../core/auth'
5 import { Video } from '../../../shared/video/video.model'
6 import { VideoComment } from './video-comment.model'
7 import { HtmlRendererService } from '@app/shared/renderer'
8
9 @Component({
10 selector: 'my-video-comment',
11 templateUrl: './video-comment.component.html',
12 styleUrls: ['./video-comment.component.scss']
13 })
14 export class VideoCommentComponent implements OnInit, OnChanges {
15 @Input() video: Video
16 @Input() comment: VideoComment
17 @Input() parentComments: VideoComment[] = []
18 @Input() commentTree: VideoCommentThreadTree
19 @Input() inReplyToCommentId: number
20 @Input() highlightedComment = false
21
22 @Output() wantedToDelete = new EventEmitter<VideoComment>()
23 @Output() wantedToReply = new EventEmitter<VideoComment>()
24 @Output() threadCreated = new EventEmitter<VideoCommentThreadTree>()
25 @Output() resetReply = new EventEmitter()
26
27 sanitizedCommentHTML = ''
28 newParentComments: VideoComment[] = []
29
30 constructor (
31 private htmlRenderer: HtmlRendererService,
32 private authService: AuthService
33 ) {}
34
35 get user () {
36 return this.authService.getUser()
37 }
38
39 ngOnInit () {
40 this.init()
41 }
42
43 ngOnChanges () {
44 this.init()
45 }
46
47 onCommentReplyCreated (createdComment: VideoComment) {
48 if (!this.commentTree) {
49 this.commentTree = {
50 comment: this.comment,
51 children: []
52 }
53
54 this.threadCreated.emit(this.commentTree)
55 }
56
57 this.commentTree.children.unshift({
58 comment: createdComment,
59 children: []
60 })
61 this.resetReply.emit()
62 }
63
64 onWantToReply (comment?: VideoComment) {
65 this.wantedToReply.emit(comment || this.comment)
66 }
67
68 onWantToDelete (comment?: VideoComment) {
69 this.wantedToDelete.emit(comment || this.comment)
70 }
71
72 isUserLoggedIn () {
73 return this.authService.isLoggedIn()
74 }
75
76 onResetReply () {
77 this.resetReply.emit()
78 }
79
80 isRemovableByUser () {
81 return this.isUserLoggedIn() &&
82 (
83 this.user.account.id === this.comment.account.id ||
84 this.user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
85 )
86 }
87
88 private init () {
89 this.sanitizedCommentHTML = this.htmlRenderer.toSafeHtml(this.comment.text)
90
91 this.newParentComments = this.parentComments.concat([ this.comment ])
92 }
93 }