PeerTube/client/src/app/videos/+video-watch/comment/video-comment.component.ts

65 lines
1.7 KiB
TypeScript
Raw Normal View History

2017-12-27 16:11:53 +01:00
import { Component, EventEmitter, Input, Output } from '@angular/core'
2018-01-03 17:25:47 +01:00
import { Account as AccountInterface } from '../../../../../../shared/models/actors'
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']
})
export class VideoCommentComponent {
@Input() video: Video
@Input() comment: VideoComment
@Input() commentTree: VideoCommentThreadTree
@Input() inReplyToCommentId: number
@Output() wantedToReply = new EventEmitter<VideoComment>()
@Output() resetReply = new EventEmitter()
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
}
2017-12-27 16:28:15 +01:00
onCommentReplyCreated (createdComment: VideoComment) {
if (!this.commentTree) {
this.commentTree = {
comment: this.comment,
children: []
}
}
this.commentTree.children.push({
comment: createdComment,
children: []
})
this.resetReply.emit()
2017-12-27 16:11:53 +01:00
}
onWantToReply () {
this.wantedToReply.emit(this.comment)
}
isUserLoggedIn () {
return this.authService.isLoggedIn()
}
// Event from child comment
onWantedToReply (comment: VideoComment) {
this.wantedToReply.emit(comment)
}
onResetReply () {
this.resetReply.emit()
}
2018-01-03 17:25:47 +01:00
getAvatarUrl (account: AccountInterface) {
return Account.GET_ACCOUNT_AVATAR_URL(account)
}
2017-12-27 16:11:53 +01:00
}