Commit 3c3870cc9590ccf22d15c6d80a228fcb88fa576d
1 parent
1af26816
Exists in
master
and in
15 other branches
fixed issue when removing comment with replies
Showing
3 changed files
with
19 additions
and
6 deletions
Show diff stats
src/app/article/comment/comments.component.ts
| @@ -34,6 +34,17 @@ export class CommentsComponent { | @@ -34,6 +34,17 @@ export class CommentsComponent { | ||
| 34 | 34 | ||
| 35 | commentAdded(comment: noosfero.CommentViewModel): void { | 35 | commentAdded(comment: noosfero.CommentViewModel): void { |
| 36 | comment.__show_reply = false; | 36 | comment.__show_reply = false; |
| 37 | + if (comment.reply_of) { | ||
| 38 | + this.comments.forEach((commentOnList) => { | ||
| 39 | + if (commentOnList.id == comment.reply_of.id) { | ||
| 40 | + if (commentOnList.replies) { | ||
| 41 | + commentOnList.replies.push(comment); | ||
| 42 | + } else { | ||
| 43 | + commentOnList.replies = [comment]; | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + }); | ||
| 47 | + } | ||
| 37 | this.comments.push(comment); | 48 | this.comments.push(comment); |
| 38 | this.resetShowReply(); | 49 | this.resetShowReply(); |
| 39 | this.$scope.$apply(); | 50 | this.$scope.$apply(); |
src/lib/ng-noosfero-api/http/restangular_service.ts
| @@ -223,7 +223,7 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | @@ -223,7 +223,7 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | ||
| 223 | restRequest = restangularObj.remove(queryParams, headers); | 223 | restRequest = restangularObj.remove(queryParams, headers); |
| 224 | 224 | ||
| 225 | restRequest | 225 | restRequest |
| 226 | - .then(this.getHandleSuccessFunction(deferred, this.modelRemovedEventEmitter)) | 226 | + .then(this.getHandleSuccessFunction(deferred, this.modelRemovedEventEmitter, obj)) |
| 227 | .catch(this.getHandleErrorFunction(deferred)); | 227 | .catch(this.getHandleErrorFunction(deferred)); |
| 228 | 228 | ||
| 229 | return deferred.promise; | 229 | return deferred.promise; |
| @@ -311,7 +311,7 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | @@ -311,7 +311,7 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | ||
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | /** HANDLERS */ | 313 | /** HANDLERS */ |
| 314 | - protected getHandleSuccessFunction<C>(deferred: ng.IDeferred<noosfero.RestResult<C | T | any>>, successEmitter: EventEmitter<T> = null): (response: restangular.IResponse) => void { | 314 | + protected getHandleSuccessFunction<C>(deferred: ng.IDeferred<noosfero.RestResult<C | T | any>>, successEmitter: EventEmitter<T> = null, currentModel: T = null): (response: restangular.IResponse) => void { |
| 315 | let self = this; | 315 | let self = this; |
| 316 | 316 | ||
| 317 | /** | 317 | /** |
| @@ -328,7 +328,11 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | @@ -328,7 +328,11 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | ||
| 328 | deferred.resolve(resultModel); | 328 | deferred.resolve(resultModel); |
| 329 | // emits the event if a successEmiter was provided in the successEmitter parameter | 329 | // emits the event if a successEmiter was provided in the successEmitter parameter |
| 330 | if (successEmitter !== null) { | 330 | if (successEmitter !== null) { |
| 331 | - successEmitter.next(resultModel.data); | 331 | + if (successEmitter !== this.modelRemovedEventEmitter) { |
| 332 | + successEmitter.next(resultModel.data); | ||
| 333 | + } else { | ||
| 334 | + successEmitter.next(currentModel !== null ? currentModel : resultModel.data); | ||
| 335 | + } | ||
| 332 | } | 336 | } |
| 333 | }; | 337 | }; |
| 334 | return successFunction; | 338 | return successFunction; |
src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts
| @@ -36,14 +36,12 @@ export class AllowCommentComponent { | @@ -36,14 +36,12 @@ export class AllowCommentComponent { | ||
| 36 | this.commentService.subscribeToModelAdded((comment: noosfero.CommentParagraph) => { | 36 | this.commentService.subscribeToModelAdded((comment: noosfero.CommentParagraph) => { |
| 37 | if (comment.paragraph_uuid === this.paragraphUuid) { | 37 | if (comment.paragraph_uuid === this.paragraphUuid) { |
| 38 | this.commentsCount += 1; | 38 | this.commentsCount += 1; |
| 39 | - this.$scope.$apply(); | ||
| 40 | }; | 39 | }; |
| 41 | }); | 40 | }); |
| 42 | 41 | ||
| 43 | this.commentService.subscribeToModelRemoved((comment: noosfero.CommentParagraph) => { | 42 | this.commentService.subscribeToModelRemoved((comment: noosfero.CommentParagraph) => { |
| 44 | if (comment.paragraph_uuid === this.paragraphUuid) { | 43 | if (comment.paragraph_uuid === this.paragraphUuid) { |
| 45 | - this.commentsCount -= 1; | ||
| 46 | - this.$scope.$apply(); | 44 | + this.commentsCount -= (comment.replies) ? 1 + comment.replies.length : 1; |
| 47 | }; | 45 | }; |
| 48 | }); | 46 | }); |
| 49 | } | 47 | } |