]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-watch/comment/video-comment.component.ts
Add hyperlink video timestamps in description
[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'
d68ebf0b 7import { HtmlRendererService, MarkdownService } 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 (
d68ebf0b 31 private htmlRenderer: HtmlRendererService,
1aa75434 32 private markdownService: MarkdownService,
e8cb4409 33 private authService: AuthService
3d9eaae3 34 ) {}
cf117aaa
C
35
36 get user () {
37 return this.authService.getUser()
4635f59d
C
38 }
39
2890b615 40 ngOnInit () {
1263fc4e
C
41 this.init()
42 }
d7e70384 43
1263fc4e
C
44 ngOnChanges () {
45 this.init()
2890b615
C
46 }
47
ae45f988
C
48 onCommentReplyCreated (createdComment: VideoComment) {
49 if (!this.commentTree) {
50 this.commentTree = {
51 comment: this.comment,
52 children: []
53 }
4cb6d457
C
54
55 this.threadCreated.emit(this.commentTree)
ae45f988
C
56 }
57
86ec3e53 58 this.commentTree.children.unshift({
ae45f988
C
59 comment: createdComment,
60 children: []
61 })
62 this.resetReply.emit()
4635f59d
C
63 }
64
4cb6d457
C
65 onWantToReply (comment?: VideoComment) {
66 this.wantedToReply.emit(comment || this.comment)
4635f59d
C
67 }
68
4cb6d457
C
69 onWantToDelete (comment?: VideoComment) {
70 this.wantedToDelete.emit(comment || this.comment)
4635f59d
C
71 }
72
4cb6d457
C
73 isUserLoggedIn () {
74 return this.authService.isLoggedIn()
4635f59d
C
75 }
76
77 onResetReply () {
78 this.resetReply.emit()
79 }
cf117aaa 80
4cb6d457 81 isRemovableByUser () {
d68ebf0b 82 return this.isUserLoggedIn() &&
4cb6d457
C
83 (
84 this.user.account.id === this.comment.account.id ||
85 this.user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
86 )
87 }
1263fc4e 88
41d71344 89 private async init () {
d68ebf0b
L
90 const safeHTML = await this.htmlRenderer.toSafeHtml(this.comment.text)
91 this.sanitizedCommentHTML = await this.markdownService.processVideoTimestamps(safeHTML)
1263fc4e
C
92 this.newParentComments = this.parentComments.concat([ this.comment ])
93 }
4635f59d 94}