]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/+video-watch/comment/video-comment.component.ts
Provide native links for description timestamps, and re-clickability for these
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / comment / video-comment.component.ts
1 import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'
2 import { UserRight } from '../../../../../../shared/models/users'
3 import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
4 import { AuthService } from '../../../core/auth'
5 import { Video } from '../../../shared/video/video.model'
6 import { VideoComment } from './video-comment.model'
7 import { MarkdownService } from '@app/shared/renderer'
8
9 @Component({
10 selector: 'my-video-comment',
11 templateUrl: './video-comment.component.html',
12 styleUrls: ['./video-comment.component.scss']
13 })
14 export class VideoCommentComponent implements OnInit, OnChanges {
15 @Input() video: Video
16 @Input() comment: VideoComment
17 @Input() parentComments: VideoComment[] = []
18 @Input() commentTree: VideoCommentThreadTree
19 @Input() inReplyToCommentId: number
20 @Input() highlightedComment = false
21
22 @Output() wantedToDelete = new EventEmitter<VideoComment>()
23 @Output() wantedToReply = new EventEmitter<VideoComment>()
24 @Output() threadCreated = new EventEmitter<VideoCommentThreadTree>()
25 @Output() resetReply = new EventEmitter()
26 @Output() timestampClicked = new EventEmitter<number>()
27
28 sanitizedCommentHTML = ''
29 newParentComments: VideoComment[] = []
30
31 constructor (
32 private markdownService: MarkdownService,
33 private authService: AuthService
34 ) {}
35
36 get user () {
37 return this.authService.getUser()
38 }
39
40 ngOnInit () {
41 this.init()
42 }
43
44 ngOnChanges () {
45 this.init()
46 }
47
48 onCommentReplyCreated (createdComment: VideoComment) {
49 if (!this.commentTree) {
50 this.commentTree = {
51 comment: this.comment,
52 children: []
53 }
54
55 this.threadCreated.emit(this.commentTree)
56 }
57
58 this.commentTree.children.unshift({
59 comment: createdComment,
60 children: []
61 })
62 this.resetReply.emit()
63 }
64
65 onWantToReply (comment?: VideoComment) {
66 this.wantedToReply.emit(comment || this.comment)
67 }
68
69 onWantToDelete (comment?: VideoComment) {
70 this.wantedToDelete.emit(comment || this.comment)
71 }
72
73 isUserLoggedIn () {
74 return this.authService.isLoggedIn()
75 }
76
77 onResetReply () {
78 this.resetReply.emit()
79 }
80
81 handleTimestampClicked (timestamp: number) {
82 this.timestampClicked.emit(timestamp)
83 }
84
85 isRemovableByUser () {
86 return this.comment.account && this.isUserLoggedIn() &&
87 (
88 this.user.account.id === this.comment.account.id ||
89 this.user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
90 )
91 }
92
93 private async init () {
94 const html = await this.markdownService.textMarkdownToHTML(this.comment.text, true)
95 this.sanitizedCommentHTML = await this.markdownService.processVideoTimestamps(html)
96 this.newParentComments = this.parentComments.concat([ this.comment ])
97 }
98 }