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') &&
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());
}

View File

@ -56,7 +56,7 @@
</button>
</ion-item>
<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-card>

View File

@ -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,10 +313,6 @@ export class CoreCommentsViewerPage implements OnDestroy {
const index = this.comments.findIndex((comment) => comment.id == deleteComment.id);
if (index >= 0) {
this.comments.splice(index, 1);
}
} else {
this.loadOfflineData();
}
this.eventsProvider.trigger(CoreCommentsProvider.COMMENTS_COUNT_CHANGED_EVENT, {
contextLevel: this.contextLevel,
@ -326,6 +322,10 @@ export class CoreCommentsViewerPage implements OnDestroy {
area: this.area,
countChange: -1,
}, this.sitesProvider.getCurrentSiteId());
}
} else {
this.loadOfflineData();
}
this.invalidateComments();