MOBILE-2877 comments: Fix comments offline load
parent
8280e5c4dd
commit
5a7bff9bb9
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
||||||
|
|
||||||
|
|
|
@ -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,10 +313,6 @@ 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);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.loadOfflineData();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.eventsProvider.trigger(CoreCommentsProvider.COMMENTS_COUNT_CHANGED_EVENT, {
|
this.eventsProvider.trigger(CoreCommentsProvider.COMMENTS_COUNT_CHANGED_EVENT, {
|
||||||
contextLevel: this.contextLevel,
|
contextLevel: this.contextLevel,
|
||||||
|
@ -326,6 +322,10 @@ export class CoreCommentsViewerPage implements OnDestroy {
|
||||||
area: this.area,
|
area: this.area,
|
||||||
countChange: -1,
|
countChange: -1,
|
||||||
}, this.sitesProvider.getCurrentSiteId());
|
}, this.sitesProvider.getCurrentSiteId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.loadOfflineData();
|
||||||
|
}
|
||||||
|
|
||||||
this.invalidateComments();
|
this.invalidateComments();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue