1 import { Component, EventEmitter, Input, Output } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
4 import { AuthService } from '../../../core/auth'
5 import { User } from '../../../shared/users'
6 import { Video } from '../../../shared/video/video.model'
7 import { VideoComment } from './video-comment.model'
8 import { VideoCommentService } from './video-comment.service'
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() wantedToReply = new EventEmitter<VideoComment>()
22 @Output() resetReply = new EventEmitter()
24 constructor (private authService: AuthService,
25 private notificationsService: NotificationsService,
26 private videoCommentService: VideoCommentService) {
29 onCommentReplyCreated (comment: VideoComment) {
30 this.videoCommentService.addCommentReply(this.video.id, this.comment.id, comment)
33 if (!this.commentTree) {
35 comment: this.comment,
40 this.commentTree.children.push({
41 comment: createdComment,
44 this.resetReply.emit()
47 err => this.notificationsService.error('Error', err.message)
52 this.wantedToReply.emit(this.comment)
56 return this.authService.isLoggedIn()
59 // Event from child comment
60 onWantedToReply (comment: VideoComment) {
61 this.wantedToReply.emit(comment)
65 this.resetReply.emit()