MOBILE-2877 comments: Fix comments offline load

main
Pau Ferrer Ocaña 2019-12-04 11:50:23 +01:00
parent 8280e5c4dd
commit 5a7bff9bb9
3 changed files with 16 additions and 13 deletions

View File

@ -86,8 +86,11 @@ export class CoreCommentsCommentsComponent implements OnChanges, OnDestroy {
if (!this.commentsCount.endsWith('+') && this.undefinedOrEqual(data, 'contextLevel') && if (!this.commentsCount.endsWith('+') && this.undefinedOrEqual(data, 'contextLevel') &&
this.undefinedOrEqual(data, 'instanceId') && this.undefinedOrEqual(data, 'component') && this.undefinedOrEqual(data, 'instanceId') && this.undefinedOrEqual(data, 'component') &&
this.undefinedOrEqual(data, 'itemId') && this.undefinedOrEqual(data, 'area') && !this.countError) { 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. // Parse and unparse string.
this.commentsCount = parseInt(this.commentsCount, 10) + data.countChange + ''; this.commentsCount = newNumber + '';
} }
}, sitesProvider.getCurrentSiteId()); }, sitesProvider.getCurrentSiteId());
} }

View File

@ -56,7 +56,7 @@
</button> </button>
</ion-item> </ion-item>
<ion-item text-wrap> <ion-item text-wrap>
<core-format-text clean="true" [text]="comment.content" [contextLevel]="contextLevel" [contextInstanceId]="instanceId" [courseId]="courseId"></core-format-text> <core-format-text [text]="comment.content" [contextLevel]="contextLevel" [contextInstanceId]="instanceId" [courseId]="courseId"></core-format-text>
</ion-item> </ion-item>
</ion-card> </ion-card>

View File

@ -133,8 +133,6 @@ export class CoreCommentsViewerPage implements OnDestroy {
return promise.catch(() => { return promise.catch(() => {
// Ignore errors. // Ignore errors.
}).then(() => {
return this.loadOfflineData();
}).then(() => { }).then(() => {
// Get comments data. // Get comments data.
return this.commentsProvider.getComments(this.contextLevel, this.instanceId, this.componentName, this.itemId, return this.commentsProvider.getComments(this.contextLevel, this.instanceId, this.componentName, this.itemId,
@ -157,6 +155,8 @@ export class CoreCommentsViewerPage implements OnDestroy {
return !!comment.delete; return !!comment.delete;
})); }));
}); });
}).then(() => {
return this.loadOfflineData();
}).catch((error) => { }).catch((error) => {
this.loadMoreError = true; // Set to prevent infinite calls with infinite-loading. this.loadMoreError = true; // Set to prevent infinite calls with infinite-loading.
if (error && this.componentName == 'assignsubmission_comments') { 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); const index = this.comments.findIndex((comment) => comment.id == deleteComment.id);
if (index >= 0) { if (index >= 0) {
this.comments.splice(index, 1); 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 { } else {
this.loadOfflineData(); 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.invalidateComments();
this.domUtils.showToast('core.comments.eventcommentdeleted', true, 3000); this.domUtils.showToast('core.comments.eventcommentdeleted', true, 3000);