2018-01-04 17:50:30 +01:00
|
|
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
|
|
|
|
import * as sanitizeHtml from 'sanitize-html'
|
2018-01-03 17:25:47 +01:00
|
|
|
import { Account as AccountInterface } from '../../../../../../shared/models/actors'
|
2018-01-04 11:19:16 +01:00
|
|
|
import { UserRight } from '../../../../../../shared/models/users'
|
2017-12-27 16:11:53 +01:00
|
|
|
import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
|
|
|
|
import { AuthService } from '../../../core/auth'
|
2018-01-03 17:25:47 +01:00
|
|
|
import { Account } from '../../../shared/account/account.model'
|
2017-12-27 16:11:53 +01:00
|
|
|
import { Video } from '../../../shared/video/video.model'
|
|
|
|
import { VideoComment } from './video-comment.model'
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-video-comment',
|
|
|
|
templateUrl: './video-comment.component.html',
|
|
|
|
styleUrls: ['./video-comment.component.scss']
|
|
|
|
})
|
2018-01-04 17:50:30 +01:00
|
|
|
export class VideoCommentComponent implements OnInit {
|
2017-12-27 16:11:53 +01:00
|
|
|
@Input() video: Video
|
|
|
|
@Input() comment: VideoComment
|
|
|
|
@Input() commentTree: VideoCommentThreadTree
|
|
|
|
@Input() inReplyToCommentId: number
|
|
|
|
|
2018-01-04 11:19:16 +01:00
|
|
|
@Output() wantedToDelete = new EventEmitter<VideoComment>()
|
2017-12-27 16:11:53 +01:00
|
|
|
@Output() wantedToReply = new EventEmitter<VideoComment>()
|
2018-01-04 11:19:16 +01:00
|
|
|
@Output() threadCreated = new EventEmitter<VideoCommentThreadTree>()
|
2017-12-27 16:11:53 +01:00
|
|
|
@Output() resetReply = new EventEmitter()
|
|
|
|
|
2018-01-04 17:50:30 +01:00
|
|
|
sanitizedCommentHTML = ''
|
|
|
|
|
2018-01-03 17:25:47 +01:00
|
|
|
constructor (private authService: AuthService) {}
|
|
|
|
|
|
|
|
get user () {
|
|
|
|
return this.authService.getUser()
|
2017-12-27 16:11:53 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 17:50:30 +01:00
|
|
|
ngOnInit () {
|
|
|
|
this.sanitizedCommentHTML = sanitizeHtml(this.comment.text, {
|
|
|
|
allowedTags: [ 'p', 'span' ]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-12-27 16:28:15 +01:00
|
|
|
onCommentReplyCreated (createdComment: VideoComment) {
|
|
|
|
if (!this.commentTree) {
|
|
|
|
this.commentTree = {
|
|
|
|
comment: this.comment,
|
|
|
|
children: []
|
|
|
|
}
|
2018-01-04 11:19:16 +01:00
|
|
|
|
|
|
|
this.threadCreated.emit(this.commentTree)
|
2017-12-27 16:28:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.commentTree.children.push({
|
|
|
|
comment: createdComment,
|
|
|
|
children: []
|
|
|
|
})
|
|
|
|
this.resetReply.emit()
|
2017-12-27 16:11:53 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 11:19:16 +01:00
|
|
|
onWantToReply (comment?: VideoComment) {
|
|
|
|
this.wantedToReply.emit(comment || this.comment)
|
2017-12-27 16:11:53 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 11:19:16 +01:00
|
|
|
onWantToDelete (comment?: VideoComment) {
|
|
|
|
this.wantedToDelete.emit(comment || this.comment)
|
2017-12-27 16:11:53 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 11:19:16 +01:00
|
|
|
isUserLoggedIn () {
|
|
|
|
return this.authService.isLoggedIn()
|
2017-12-27 16:11:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onResetReply () {
|
|
|
|
this.resetReply.emit()
|
|
|
|
}
|
2018-01-03 17:25:47 +01:00
|
|
|
|
|
|
|
getAvatarUrl (account: AccountInterface) {
|
|
|
|
return Account.GET_ACCOUNT_AVATAR_URL(account)
|
|
|
|
}
|
2018-01-04 11:19:16 +01:00
|
|
|
|
|
|
|
isRemovableByUser () {
|
|
|
|
return this.isUserLoggedIn() &&
|
|
|
|
(
|
|
|
|
this.user.account.id === this.comment.account.id ||
|
|
|
|
this.user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
|
|
|
|
)
|
|
|
|
}
|
2017-12-27 16:11:53 +01:00
|
|
|
}
|