X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fvideos%2F%2Bvideo-watch%2Fcomment%2Fvideo-comment.component.ts;h=23ff20aad82ad3c061eccccb9b97c5ceadb68919;hb=1aa7543403f278ad88d64e368e77bcb3efa58dd7;hp=b8e2acd52f11316f9ca37a68e68df539fcf208ed;hpb=4635f59d7c3fea4b97029f10886c62fdf38b2084;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/videos/+video-watch/comment/video-comment.component.ts b/client/src/app/videos/+video-watch/comment/video-comment.component.ts index b8e2acd52..23ff20aad 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment.component.ts @@ -1,67 +1,93 @@ -import { Component, EventEmitter, Input, Output } from '@angular/core' -import { NotificationsService } from 'angular2-notifications' +import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core' +import { UserRight } from '../../../../../../shared/models/users' import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model' import { AuthService } from '../../../core/auth' -import { User } from '../../../shared/users' import { Video } from '../../../shared/video/video.model' import { VideoComment } from './video-comment.model' -import { VideoCommentService } from './video-comment.service' +import { MarkdownService } from '@app/shared/renderer' @Component({ selector: 'my-video-comment', templateUrl: './video-comment.component.html', styleUrls: ['./video-comment.component.scss'] }) -export class VideoCommentComponent { +export class VideoCommentComponent implements OnInit, OnChanges { @Input() video: Video @Input() comment: VideoComment + @Input() parentComments: VideoComment[] = [] @Input() commentTree: VideoCommentThreadTree @Input() inReplyToCommentId: number + @Input() highlightedComment = false + @Output() wantedToDelete = new EventEmitter() @Output() wantedToReply = new EventEmitter() + @Output() threadCreated = new EventEmitter() @Output() resetReply = new EventEmitter() - constructor (private authService: AuthService, - private notificationsService: NotificationsService, - private videoCommentService: VideoCommentService) { + sanitizedCommentHTML = '' + newParentComments: VideoComment[] = [] + + constructor ( + private markdownService: MarkdownService, + private authService: AuthService + ) {} + + get user () { + return this.authService.getUser() } - onCommentReplyCreated (comment: VideoComment) { - this.videoCommentService.addCommentReply(this.video.id, this.comment.id, comment) - .subscribe( - createdComment => { - if (!this.commentTree) { - this.commentTree = { - comment: this.comment, - children: [] - } - } - - this.commentTree.children.push({ - comment: createdComment, - children: [] - }) - this.resetReply.emit() - }, - - err => this.notificationsService.error('Error', err.message) - ) + ngOnInit () { + this.init() } - onWantToReply () { - this.wantedToReply.emit(this.comment) + ngOnChanges () { + this.init() } - isUserLoggedIn () { - return this.authService.isLoggedIn() + onCommentReplyCreated (createdComment: VideoComment) { + if (!this.commentTree) { + this.commentTree = { + comment: this.comment, + children: [] + } + + this.threadCreated.emit(this.commentTree) + } + + this.commentTree.children.unshift({ + comment: createdComment, + children: [] + }) + this.resetReply.emit() + } + + onWantToReply (comment?: VideoComment) { + this.wantedToReply.emit(comment || this.comment) } - // Event from child comment - onWantedToReply (comment: VideoComment) { - this.wantedToReply.emit(comment) + onWantToDelete (comment?: VideoComment) { + this.wantedToDelete.emit(comment || this.comment) + } + + isUserLoggedIn () { + return this.authService.isLoggedIn() } onResetReply () { this.resetReply.emit() } + + isRemovableByUser () { + return this.comment.account && this.isUserLoggedIn() && + ( + this.user.account.id === this.comment.account.id || + this.user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT) + ) + } + + private async init () { + this.sanitizedCommentHTML = await this.markdownService.textMarkdownToHTML(this.comment.text, true) + + this.newParentComments = this.parentComments.concat([ this.comment ]) + } }