X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Bvideos%2F%2Bvideo-watch%2Fcomment%2Fvideo-comments.component.ts;h=210236b61133856fe23f56afdb8737f75a484b47;hb=fa12eacc014aae8094d108634371640f2695bf9f;hp=df0018ec65214936f9225fa1a4c2ccace6386d15;hpb=1942f11d5ee6926ad93dc1b79fae18325ba5de18;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+videos/+video-watch/comment/video-comments.component.ts b/client/src/app/+videos/+video-watch/comment/video-comments.component.ts index df0018ec6..210236b61 100644 --- a/client/src/app/+videos/+video-watch/comment/video-comments.component.ts +++ b/client/src/app/+videos/+video-watch/comment/video-comments.component.ts @@ -4,10 +4,7 @@ import { ActivatedRoute } from '@angular/router' 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', @@ -23,13 +20,20 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { comments: VideoComment[] = [] highlightedThread: VideoComment + sort = '-createdAt' + componentPagination: ComponentPagination = { currentPage: 1, itemsPerPage: 10, totalItems: null } + totalNotDeletedComments: number + inReplyToCommentId: number + commentReplyRedraftValue: string + commentThreadRedraftValue: string + threadComments: { [ id: number ]: VideoCommentThreadTree } = {} threadLoading: { [ id: number ]: boolean } = {} @@ -45,7 +49,6 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { private confirmService: ConfirmService, private videoCommentService: VideoCommentService, private activatedRoute: ActivatedRoute, - private i18n: I18n, private hooks: HooksService ) {} @@ -124,6 +127,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { res => { this.comments = this.comments.concat(res.data) this.componentPagination.totalItems = res.total + this.totalNotDeletedComments = res.totalNotDeletedComments this.onDataSubject.next(res.data) this.hooks.runAction('action:video-watch.video-threads.loaded', 'video-watch', { data: this.componentPagination }) @@ -135,6 +139,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { onCommentThreadCreated (comment: VideoComment) { this.comments.unshift(comment) + this.commentThreadRedraftValue = undefined } onWantedToReply (comment: VideoComment) { @@ -143,6 +148,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { onResetReply () { this.inReplyToCommentId = undefined + this.commentReplyRedraftValue = undefined } onThreadCreated (commentTree: VideoCommentThreadTree) { @@ -160,17 +166,19 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { 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 { 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( @@ -187,6 +195,26 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { 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(//g, '\r\n') + + if (commentToRedraft.threadId === commentToRedraft.id) { + this.commentThreadRedraftValue = commentToRedraftText + } else { + this.commentReplyRedraftValue = commentToRedraftText + } + + } } isUserLoggedIn () { @@ -217,6 +245,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { this.inReplyToCommentId = undefined this.componentPagination.currentPage = 1 this.componentPagination.totalItems = null + this.totalNotDeletedComments = null this.syndicationItems = this.videoCommentService.getVideoCommentsFeeds(this.video.uuid) this.loadMoreThreads()