From 5a7bff9bb92c795274a222ca17abc3db559c9c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 4 Dec 2019 11:50:23 +0100 Subject: [PATCH] MOBILE-2877 comments: Fix comments offline load --- .../comments/components/comments/comments.ts | 5 ++++- src/core/comments/pages/viewer/viewer.html | 2 +- src/core/comments/pages/viewer/viewer.ts | 22 +++++++++---------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/core/comments/components/comments/comments.ts b/src/core/comments/components/comments/comments.ts index 9f8408442..442f58b06 100644 --- a/src/core/comments/components/comments/comments.ts +++ b/src/core/comments/components/comments/comments.ts @@ -86,8 +86,11 @@ export class CoreCommentsCommentsComponent implements OnChanges, OnDestroy { if (!this.commentsCount.endsWith('+') && this.undefinedOrEqual(data, 'contextLevel') && this.undefinedOrEqual(data, 'instanceId') && this.undefinedOrEqual(data, 'component') && this.undefinedOrEqual(data, 'itemId') && this.undefinedOrEqual(data, 'area') && !this.countError) { + let newNumber = parseInt(this.commentsCount, 10) + data.countChange; + newNumber = newNumber >= 0 ? newNumber : 0; + // Parse and unparse string. - this.commentsCount = parseInt(this.commentsCount, 10) + data.countChange + ''; + this.commentsCount = newNumber + ''; } }, sitesProvider.getCurrentSiteId()); } diff --git a/src/core/comments/pages/viewer/viewer.html b/src/core/comments/pages/viewer/viewer.html index 40eadf01b..6c4678862 100644 --- a/src/core/comments/pages/viewer/viewer.html +++ b/src/core/comments/pages/viewer/viewer.html @@ -56,7 +56,7 @@ - + diff --git a/src/core/comments/pages/viewer/viewer.ts b/src/core/comments/pages/viewer/viewer.ts index a935d0544..678769992 100644 --- a/src/core/comments/pages/viewer/viewer.ts +++ b/src/core/comments/pages/viewer/viewer.ts @@ -133,8 +133,6 @@ export class CoreCommentsViewerPage implements OnDestroy { return promise.catch(() => { // Ignore errors. - }).then(() => { - return this.loadOfflineData(); }).then(() => { // Get comments data. return this.commentsProvider.getComments(this.contextLevel, this.instanceId, this.componentName, this.itemId, @@ -157,6 +155,8 @@ export class CoreCommentsViewerPage implements OnDestroy { return !!comment.delete; })); }); + }).then(() => { + return this.loadOfflineData(); }).catch((error) => { this.loadMoreError = true; // Set to prevent infinite calls with infinite-loading. if (error && this.componentName == 'assignsubmission_comments') { @@ -313,20 +313,20 @@ export class CoreCommentsViewerPage implements OnDestroy { const index = this.comments.findIndex((comment) => comment.id == deleteComment.id); if (index >= 0) { this.comments.splice(index, 1); + + this.eventsProvider.trigger(CoreCommentsProvider.COMMENTS_COUNT_CHANGED_EVENT, { + contextLevel: this.contextLevel, + instanceId: this.instanceId, + component: this.componentName, + itemId: this.itemId, + area: this.area, + countChange: -1, + }, this.sitesProvider.getCurrentSiteId()); } } else { this.loadOfflineData(); } - this.eventsProvider.trigger(CoreCommentsProvider.COMMENTS_COUNT_CHANGED_EVENT, { - contextLevel: this.contextLevel, - instanceId: this.instanceId, - component: this.componentName, - itemId: this.itemId, - area: this.area, - countChange: -1, - }, this.sitesProvider.getCurrentSiteId()); - this.invalidateComments(); this.domUtils.showToast('core.comments.eventcommentdeleted', true, 3000);