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