]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-watch/comment/video-comment.component.ts
Handle line feeds in comments
[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'
2890b615 2import * as sanitizeHtml from 'sanitize-html'
cf117aaa 3import { Account as AccountInterface } from '../../../../../../shared/models/actors'
4cb6d457 4import { UserRight } from '../../../../../../shared/models/users'
4635f59d
C
5import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
6import { AuthService } from '../../../core/auth'
cf117aaa 7import { Account } from '../../../shared/account/account.model'
4635f59d
C
8import { Video } from '../../../shared/video/video.model'
9import { 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})
1263fc4e 16export class VideoCommentComponent implements OnInit, OnChanges {
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
1263fc4e 22 @Input() highlightedComment = false
4635f59d 23
4cb6d457 24 @Output() wantedToDelete = new EventEmitter<VideoComment>()
4635f59d 25 @Output() wantedToReply = new EventEmitter<VideoComment>()
4cb6d457 26 @Output() threadCreated = new EventEmitter<VideoCommentThreadTree>()
4635f59d
C
27 @Output() resetReply = new EventEmitter()
28
2890b615 29 sanitizedCommentHTML = ''
d7e70384 30 newParentComments = []
2890b615 31
cf117aaa
C
32 constructor (private authService: AuthService) {}
33
34 get user () {
35 return this.authService.getUser()
4635f59d
C
36 }
37
2890b615 38 ngOnInit () {
1263fc4e
C
39 this.init()
40 }
d7e70384 41
1263fc4e
C
42 ngOnChanges () {
43 this.init()
2890b615
C
44 }
45
ae45f988
C
46 onCommentReplyCreated (createdComment: VideoComment) {
47 if (!this.commentTree) {
48 this.commentTree = {
49 comment: this.comment,
50 children: []
51 }
4cb6d457
C
52
53 this.threadCreated.emit(this.commentTree)
ae45f988
C
54 }
55
56 this.commentTree.children.push({
57 comment: createdComment,
58 children: []
59 })
60 this.resetReply.emit()
4635f59d
C
61 }
62
4cb6d457
C
63 onWantToReply (comment?: VideoComment) {
64 this.wantedToReply.emit(comment || this.comment)
4635f59d
C
65 }
66
4cb6d457
C
67 onWantToDelete (comment?: VideoComment) {
68 this.wantedToDelete.emit(comment || this.comment)
4635f59d
C
69 }
70
4cb6d457
C
71 isUserLoggedIn () {
72 return this.authService.isLoggedIn()
4635f59d
C
73 }
74
75 onResetReply () {
76 this.resetReply.emit()
77 }
cf117aaa
C
78
79 getAvatarUrl (account: AccountInterface) {
80 return Account.GET_ACCOUNT_AVATAR_URL(account)
81 }
4cb6d457
C
82
83 isRemovableByUser () {
84 return this.isUserLoggedIn() &&
85 (
86 this.user.account.id === this.comment.account.id ||
87 this.user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
88 )
89 }
1263fc4e
C
90
91 private init () {
92 this.sanitizedCommentHTML = sanitizeHtml(this.comment.text, {
5de8a55a 93 allowedTags: [ 'p', 'span', 'br' ]
1263fc4e
C
94 })
95
96 this.newParentComments = this.parentComments.concat([ this.comment ])
97 }
4635f59d 98}