import { AuthService, ComponentPagination, ConfirmService, hasMoreItems, Notifier, User } from '@app/core'
import { HooksService } from '@app/core/plugins/hooks.service'
import { Syndication, VideoDetails } from '@app/shared/shared-main'
-import { I18n } from '@ngx-translate/i18n-polyfill'
-import { VideoCommentThreadTree } from './video-comment-thread-tree.model'
-import { VideoComment } from './video-comment.model'
-import { VideoCommentService } from './video-comment.service'
+import { VideoComment, VideoCommentService, VideoCommentThreadTree } from '@app/shared/shared-video-comment'
@Component({
selector: 'my-video-comments',
totalItems: null
}
inReplyToCommentId: number
+ commentReplyRedraftValue: string
+ commentThreadRedraftValue: string
threadComments: { [ id: number ]: VideoCommentThreadTree } = {}
threadLoading: { [ id: number ]: boolean } = {}
private confirmService: ConfirmService,
private videoCommentService: VideoCommentService,
private activatedRoute: ActivatedRoute,
- private i18n: I18n,
private hooks: HooksService
) {}
onCommentThreadCreated (comment: VideoComment) {
this.comments.unshift(comment)
+ this.commentThreadRedraftValue = undefined
}
onWantedToReply (comment: VideoComment) {
onResetReply () {
this.inReplyToCommentId = undefined
+ this.commentReplyRedraftValue = undefined
}
onThreadCreated (commentTree: VideoCommentThreadTree) {
this.timestampClicked.emit(timestamp)
}
- async onWantedToDelete (commentToDelete: VideoComment) {
- let message = 'Do you really want to delete this comment?'
-
+ async onWantedToDelete (
+ commentToDelete: VideoComment,
+ title = $localize`Delete`,
+ message = $localize`Do you really want to delete this comment?`
+ ): Promise<boolean> {
if (commentToDelete.isLocal || this.video.isLocal) {
- message += this.i18n(' The deletion will be sent to remote instances so they can reflect the change.')
+ message += $localize` The deletion will be sent to remote instances so they can reflect the change.`
} else {
- message += this.i18n(' It is a remote comment, so the deletion will only be effective on your instance.')
+ message += $localize` It is a remote comment, so the deletion will only be effective on your instance.`
}
- const res = await this.confirmService.confirm(message, this.i18n('Delete'))
- if (res === false) return
+ const res = await this.confirmService.confirm(message, title)
+ if (res === false) return false
this.videoCommentService.deleteVideoComment(commentToDelete.videoId, commentToDelete.id)
.subscribe(
err => this.notifier.error(err.message)
)
+
+ return true
+ }
+
+ async onWantedToRedraft (commentToRedraft: VideoComment) {
+ const confirm = await this.onWantedToDelete(commentToRedraft, $localize`Delete and re-draft`, $localize`Do you really want to delete and re-draft this comment?`)
+
+ if (confirm) {
+ this.inReplyToCommentId = commentToRedraft.inReplyToCommentId
+
+ // Restore line feed for editing
+ const commentToRedraftText = commentToRedraft.text.replace(/<br.?\/?>/g, '\r\n')
+
+ if (commentToRedraft.threadId === commentToRedraft.id) {
+ this.commentThreadRedraftValue = commentToRedraftText
+ } else {
+ this.commentReplyRedraftValue = commentToRedraftText
+ }
+
+ }
}
isUserLoggedIn () {