1 import { Component, EventEmitter, Input, 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 {
18 @Input() comment: VideoComment
19 @Input() commentTree: VideoCommentThreadTree
20 @Input() inReplyToCommentId: number
22 @Output() wantedToDelete = new EventEmitter<VideoComment>()
23 @Output() wantedToReply = new EventEmitter<VideoComment>()
24 @Output() threadCreated = new EventEmitter<VideoCommentThreadTree>()
25 @Output() resetReply = new EventEmitter()
27 sanitizedCommentHTML = ''
29 constructor (private authService: AuthService) {}
32 return this.authService.getUser()
36 this.sanitizedCommentHTML = sanitizeHtml(this.comment.text, {
37 allowedTags: [ 'p', 'span' ]
41 onCommentReplyCreated (createdComment: VideoComment) {
42 if (!this.commentTree) {
44 comment: this.comment,
48 this.threadCreated.emit(this.commentTree)
51 this.commentTree.children.push({
52 comment: createdComment,
55 this.resetReply.emit()
58 onWantToReply (comment?: VideoComment) {
59 this.wantedToReply.emit(comment || this.comment)
62 onWantToDelete (comment?: VideoComment) {
63 this.wantedToDelete.emit(comment || this.comment)
67 return this.authService.isLoggedIn()
71 this.resetReply.emit()
74 getAvatarUrl (account: AccountInterface) {
75 return Account.GET_ACCOUNT_AVATAR_URL(account)
78 isRemovableByUser () {
79 return this.isUserLoggedIn() &&
81 this.user.account.id === this.comment.account.id ||
82 this.user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)