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