1 import { Component, EventEmitter, Input, Output } from '@angular/core'
2 import { Account as AccountInterface } from '../../../../../../shared/models/actors'
3 import { UserRight } from '../../../../../../shared/models/users'
4 import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
5 import { AuthService } from '../../../core/auth'
6 import { Account } from '../../../shared/account/account.model'
7 import { Video } from '../../../shared/video/video.model'
8 import { VideoComment } from './video-comment.model'
11 selector: 'my-video-comment',
12 templateUrl: './video-comment.component.html',
13 styleUrls: ['./video-comment.component.scss']
15 export class VideoCommentComponent {
17 @Input() comment: VideoComment
18 @Input() commentTree: VideoCommentThreadTree
19 @Input() inReplyToCommentId: number
21 @Output() wantedToDelete = new EventEmitter<VideoComment>()
22 @Output() wantedToReply = new EventEmitter<VideoComment>()
23 @Output() threadCreated = new EventEmitter<VideoCommentThreadTree>()
24 @Output() resetReply = new EventEmitter()
26 constructor (private authService: AuthService) {}
29 return this.authService.getUser()
32 onCommentReplyCreated (createdComment: VideoComment) {
33 if (!this.commentTree) {
35 comment: this.comment,
39 this.threadCreated.emit(this.commentTree)
42 this.commentTree.children.push({
43 comment: createdComment,
46 this.resetReply.emit()
49 onWantToReply (comment?: VideoComment) {
50 this.wantedToReply.emit(comment || this.comment)
53 onWantToDelete (comment?: VideoComment) {
54 this.wantedToDelete.emit(comment || this.comment)
58 return this.authService.isLoggedIn()
62 this.resetReply.emit()
65 getAvatarUrl (account: AccountInterface) {
66 return Account.GET_ACCOUNT_AVATAR_URL(account)
69 isRemovableByUser () {
70 return this.isUserLoggedIn() &&
72 this.user.account.id === this.comment.account.id ||
73 this.user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)