1 import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'
2 import * as sanitizeHtml from 'sanitize-html'
3 import { Account as AccountInterface } from '../../../../../../shared/models/actors'
4 import { UserRight } from '../../../../../../shared/models/users'
5 import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
6 import { AuthService } from '../../../core/auth'
7 import { Account } from '../../../shared/account/account.model'
8 import { Video } from '../../../shared/video/video.model'
9 import { VideoComment } from './video-comment.model'
12 selector: 'my-video-comment',
13 templateUrl: './video-comment.component.html',
14 styleUrls: ['./video-comment.component.scss']
16 export class VideoCommentComponent implements OnInit, OnChanges {
18 @Input() comment: VideoComment
19 @Input() parentComments: VideoComment[] = []
20 @Input() commentTree: VideoCommentThreadTree
21 @Input() inReplyToCommentId: number
22 @Input() highlightedComment = false
24 @Output() wantedToDelete = new EventEmitter<VideoComment>()
25 @Output() wantedToReply = new EventEmitter<VideoComment>()
26 @Output() threadCreated = new EventEmitter<VideoCommentThreadTree>()
27 @Output() resetReply = new EventEmitter()
29 sanitizedCommentHTML = ''
30 newParentComments = []
32 constructor (private authService: AuthService) {}
35 return this.authService.getUser()
46 onCommentReplyCreated (createdComment: VideoComment) {
47 if (!this.commentTree) {
49 comment: this.comment,
53 this.threadCreated.emit(this.commentTree)
56 this.commentTree.children.push({
57 comment: createdComment,
60 this.resetReply.emit()
63 onWantToReply (comment?: VideoComment) {
64 this.wantedToReply.emit(comment || this.comment)
67 onWantToDelete (comment?: VideoComment) {
68 this.wantedToDelete.emit(comment || this.comment)
72 return this.authService.isLoggedIn()
76 this.resetReply.emit()
79 getAvatarUrl (account: AccountInterface) {
80 return Account.GET_ACCOUNT_AVATAR_URL(account)
83 isRemovableByUser () {
84 return this.isUserLoggedIn() &&
86 this.user.account.id === this.comment.account.id ||
87 this.user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
92 this.sanitizedCommentHTML = sanitizeHtml(this.comment.text, {
93 allowedTags: [ 'p', 'span' ]
96 this.newParentComments = this.parentComments.concat([ this.comment ])