]>
Commit | Line | Data |
---|---|---|
2890b615 C |
1 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' |
2 | import * as sanitizeHtml from 'sanitize-html' | |
cf117aaa | 3 | import { Account as AccountInterface } from '../../../../../../shared/models/actors' |
4cb6d457 | 4 | import { UserRight } from '../../../../../../shared/models/users' |
4635f59d C |
5 | import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model' |
6 | import { AuthService } from '../../../core/auth' | |
cf117aaa | 7 | import { Account } from '../../../shared/account/account.model' |
4635f59d C |
8 | import { Video } from '../../../shared/video/video.model' |
9 | import { VideoComment } from './video-comment.model' | |
4635f59d C |
10 | |
11 | @Component({ | |
12 | selector: 'my-video-comment', | |
13 | templateUrl: './video-comment.component.html', | |
14 | styleUrls: ['./video-comment.component.scss'] | |
15 | }) | |
2890b615 | 16 | export class VideoCommentComponent implements OnInit { |
4635f59d C |
17 | @Input() video: Video |
18 | @Input() comment: VideoComment | |
d7e70384 | 19 | @Input() parentComments: VideoComment[] = [] |
4635f59d C |
20 | @Input() commentTree: VideoCommentThreadTree |
21 | @Input() inReplyToCommentId: number | |
22 | ||
4cb6d457 | 23 | @Output() wantedToDelete = new EventEmitter<VideoComment>() |
4635f59d | 24 | @Output() wantedToReply = new EventEmitter<VideoComment>() |
4cb6d457 | 25 | @Output() threadCreated = new EventEmitter<VideoCommentThreadTree>() |
4635f59d C |
26 | @Output() resetReply = new EventEmitter() |
27 | ||
2890b615 | 28 | sanitizedCommentHTML = '' |
d7e70384 | 29 | newParentComments = [] |
2890b615 | 30 | |
cf117aaa C |
31 | constructor (private authService: AuthService) {} |
32 | ||
33 | get user () { | |
34 | return this.authService.getUser() | |
4635f59d C |
35 | } |
36 | ||
2890b615 C |
37 | ngOnInit () { |
38 | this.sanitizedCommentHTML = sanitizeHtml(this.comment.text, { | |
39 | allowedTags: [ 'p', 'span' ] | |
40 | }) | |
d7e70384 C |
41 | |
42 | this.newParentComments = this.parentComments.concat([ this.comment ]) | |
2890b615 C |
43 | } |
44 | ||
ae45f988 C |
45 | onCommentReplyCreated (createdComment: VideoComment) { |
46 | if (!this.commentTree) { | |
47 | this.commentTree = { | |
48 | comment: this.comment, | |
49 | children: [] | |
50 | } | |
4cb6d457 C |
51 | |
52 | this.threadCreated.emit(this.commentTree) | |
ae45f988 C |
53 | } |
54 | ||
55 | this.commentTree.children.push({ | |
56 | comment: createdComment, | |
57 | children: [] | |
58 | }) | |
59 | this.resetReply.emit() | |
4635f59d C |
60 | } |
61 | ||
4cb6d457 C |
62 | onWantToReply (comment?: VideoComment) { |
63 | this.wantedToReply.emit(comment || this.comment) | |
4635f59d C |
64 | } |
65 | ||
4cb6d457 C |
66 | onWantToDelete (comment?: VideoComment) { |
67 | this.wantedToDelete.emit(comment || this.comment) | |
4635f59d C |
68 | } |
69 | ||
4cb6d457 C |
70 | isUserLoggedIn () { |
71 | return this.authService.isLoggedIn() | |
4635f59d C |
72 | } |
73 | ||
74 | onResetReply () { | |
75 | this.resetReply.emit() | |
76 | } | |
cf117aaa C |
77 | |
78 | getAvatarUrl (account: AccountInterface) { | |
79 | return Account.GET_ACCOUNT_AVATAR_URL(account) | |
80 | } | |
4cb6d457 C |
81 | |
82 | isRemovableByUser () { | |
83 | return this.isUserLoggedIn() && | |
84 | ( | |
85 | this.user.account.id === this.comment.account.id || | |
86 | this.user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT) | |
87 | ) | |
88 | } | |
4635f59d | 89 | } |