export class VideoCommentAddComponent extends FormReactive implements OnChanges, OnInit {
@Input() user: User
@Input() video: Video
- @Input() parentComment: VideoComment
- @Input() parentComments: VideoComment[]
+ @Input() parentComment?: VideoComment
+ @Input() parentComments?: VideoComment[]
@Input() focusOnInit = false
@Input() textValue?: string
- @Input() commentThread?: boolean
@Output() commentCreated = new EventEmitter<VideoComment>()
@Output() cancel = new EventEmitter()
})
if (this.user) {
- if (this.commentThread) {
+ if (!this.parentComment) {
this.addingCommentButtonValue = this.i18n('Comment')
} else {
this.addingCommentButtonValue = this.i18n('Reply')
}
- if (this.textValue) {
- this.patchTextValue(this.textValue, this.focusOnInit)
- return
- }
-
- if (this.parentComment) {
- const mentions = this.parentComments
- .filter(c => c.account && c.account.id !== this.user.account.id) // Don't add mention of ourselves
- .map(c => '@' + c.by)
-
- const mentionsSet = new Set(mentions)
- const mentionsText = Array.from(mentionsSet).join(' ') + ' '
-
- this.patchTextValue(mentionsText, this.focusOnInit)
- }
+ this.initTextValue()
}
}
.addCommentThread(this.video.id, commentCreate)
}
+ private initTextValue () {
+ if (this.textValue) {
+ this.patchTextValue(this.textValue, this.focusOnInit)
+ return
+ }
+
+ if (this.parentComment) {
+ const mentions = this.parentComments
+ .filter(c => c.account && c.account.id !== this.user.account.id) // Don't add mention of ourselves
+ .map(c => '@' + c.by)
+
+ const mentionsSet = new Set(mentions)
+ const mentionsText = Array.from(mentionsSet).join(' ') + ' '
+
+ this.patchTextValue(mentionsText, this.focusOnInit)
+ }
+ }
+
private patchTextValue (text: string, focus: boolean) {
setTimeout(() => {
if (focus) {
this.resetReply.emit()
- delete this.redraftValue
+ this.redraftValue = undefined
}
onWantToReply (comment?: VideoComment) {
($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
}
+ isNotDeletedOrDeletedWithReplies () {
+ return !this.comment.isDeleted || this.comment.isDeleted && this.comment.totalReplies !== 0
+ }
+
private getUserIfNeeded (account: Account) {
if (!account.userId) return
if (!this.authService.isLoggedIn()) return
onCommentThreadCreated (comment: VideoComment) {
this.comments.unshift(comment)
- delete this.commentThreadRedraftValue
+ this.commentThreadRedraftValue = undefined
}
onWantedToReply (comment: VideoComment) {
onResetReply () {
this.inReplyToCommentId = undefined
- delete this.commentReplyRedraftValue
+ this.commentReplyRedraftValue = undefined
}
onThreadCreated (commentTree: VideoCommentThreadTree) {