]>
Commit | Line | Data |
---|---|---|
1263fc4e | 1 | import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core' |
4cb6d457 | 2 | import { UserRight } from '../../../../../../shared/models/users' |
4635f59d C |
3 | import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model' |
4 | import { AuthService } from '../../../core/auth' | |
4635f59d C |
5 | import { Video } from '../../../shared/video/video.model' |
6 | import { VideoComment } from './video-comment.model' | |
b29bf61d | 7 | import { 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 | 14 | export 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 | 25 | @Output() resetReply = new EventEmitter() |
b29bf61d | 26 | @Output() timestampClicked = new EventEmitter<number>() |
4635f59d | 27 | |
2890b615 | 28 | sanitizedCommentHTML = '' |
c199c427 | 29 | newParentComments: VideoComment[] = [] |
2890b615 | 30 | |
3d9eaae3 | 31 | constructor ( |
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 | |
b29bf61d RK |
81 | handleTimestampClicked (timestamp: number) { |
82 | this.timestampClicked.emit(timestamp) | |
83 | } | |
84 | ||
4cb6d457 | 85 | isRemovableByUser () { |
b29bf61d | 86 | return this.comment.account && this.isUserLoggedIn() && |
4cb6d457 C |
87 | ( |
88 | this.user.account.id === this.comment.account.id || | |
89 | this.user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT) | |
90 | ) | |
91 | } | |
1263fc4e | 92 | |
41d71344 | 93 | private async init () { |
b29bf61d RK |
94 | const html = await this.markdownService.textMarkdownToHTML(this.comment.text, true) |
95 | this.sanitizedCommentHTML = await this.markdownService.processVideoTimestamps(html) | |
1263fc4e C |
96 | this.newParentComments = this.parentComments.concat([ this.comment ]) |
97 | } | |
4635f59d | 98 | } |