From 3c3870cc9590ccf22d15c6d80a228fcb88fa576d Mon Sep 17 00:00:00 2001 From: Abner Oliveira Date: Fri, 27 May 2016 17:57:43 -0300 Subject: [PATCH] fixed issue when removing comment with replies --- src/app/article/comment/comments.component.ts | 11 +++++++++++ src/lib/ng-noosfero-api/http/restangular_service.ts | 10 +++++++--- src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts | 4 +--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/app/article/comment/comments.component.ts b/src/app/article/comment/comments.component.ts index 1e510d9..c830e81 100644 --- a/src/app/article/comment/comments.component.ts +++ b/src/app/article/comment/comments.component.ts @@ -34,6 +34,17 @@ export class CommentsComponent { commentAdded(comment: noosfero.CommentViewModel): void { comment.__show_reply = false; + if (comment.reply_of) { + this.comments.forEach((commentOnList) => { + if (commentOnList.id == comment.reply_of.id) { + if (commentOnList.replies) { + commentOnList.replies.push(comment); + } else { + commentOnList.replies = [comment]; + } + } + }); + } this.comments.push(comment); this.resetShowReply(); this.$scope.$apply(); diff --git a/src/lib/ng-noosfero-api/http/restangular_service.ts b/src/lib/ng-noosfero-api/http/restangular_service.ts index 697d28e..75d063d 100644 --- a/src/lib/ng-noosfero-api/http/restangular_service.ts +++ b/src/lib/ng-noosfero-api/http/restangular_service.ts @@ -223,7 +223,7 @@ export abstract class RestangularService { restRequest = restangularObj.remove(queryParams, headers); restRequest - .then(this.getHandleSuccessFunction(deferred, this.modelRemovedEventEmitter)) + .then(this.getHandleSuccessFunction(deferred, this.modelRemovedEventEmitter, obj)) .catch(this.getHandleErrorFunction(deferred)); return deferred.promise; @@ -311,7 +311,7 @@ export abstract class RestangularService { } /** HANDLERS */ - protected getHandleSuccessFunction(deferred: ng.IDeferred>, successEmitter: EventEmitter = null): (response: restangular.IResponse) => void { + protected getHandleSuccessFunction(deferred: ng.IDeferred>, successEmitter: EventEmitter = null, currentModel: T = null): (response: restangular.IResponse) => void { let self = this; /** @@ -328,7 +328,11 @@ export abstract class RestangularService { deferred.resolve(resultModel); // emits the event if a successEmiter was provided in the successEmitter parameter if (successEmitter !== null) { - successEmitter.next(resultModel.data); + if (successEmitter !== this.modelRemovedEventEmitter) { + successEmitter.next(resultModel.data); + } else { + successEmitter.next(currentModel !== null ? currentModel : resultModel.data); + } } }; return successFunction; diff --git a/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts b/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts index a091bf6..2175cbd 100644 --- a/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts +++ b/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts @@ -36,14 +36,12 @@ export class AllowCommentComponent { this.commentService.subscribeToModelAdded((comment: noosfero.CommentParagraph) => { if (comment.paragraph_uuid === this.paragraphUuid) { this.commentsCount += 1; - this.$scope.$apply(); }; }); this.commentService.subscribeToModelRemoved((comment: noosfero.CommentParagraph) => { if (comment.paragraph_uuid === this.paragraphUuid) { - this.commentsCount -= 1; - this.$scope.$apply(); + this.commentsCount -= (comment.replies) ? 1 + comment.replies.length : 1; }; }); } -- libgit2 0.21.2