MOBILE-2877 comments: Invalidate comments count
parent
9e91cf14e6
commit
dc65d4a00d
|
@ -169,6 +169,10 @@ export class AddonBlogEntriesComponent implements OnInit {
|
||||||
* @param {any} refresher Refresher instance.
|
* @param {any} refresher Refresher instance.
|
||||||
*/
|
*/
|
||||||
refresh(refresher?: any): void {
|
refresh(refresher?: any): void {
|
||||||
|
this.entries.forEach((entry) => {
|
||||||
|
this.commentsProvider.invalidateCommentsData('user', entry.userid, this.component, entry.id, 'format_blog');
|
||||||
|
});
|
||||||
|
|
||||||
this.blogProvider.invalidateEntries(this.filter).finally(() => {
|
this.blogProvider.invalidateEntries(this.filter).finally(() => {
|
||||||
this.fetchEntries(true).finally(() => {
|
this.fetchEntries(true).finally(() => {
|
||||||
if (refresher) {
|
if (refresher) {
|
||||||
|
|
|
@ -218,6 +218,10 @@ export class AddonModDataEntryPage implements OnDestroy {
|
||||||
|
|
||||||
promises.push(this.dataProvider.invalidateDatabaseData(this.courseId));
|
promises.push(this.dataProvider.invalidateDatabaseData(this.courseId));
|
||||||
if (this.data) {
|
if (this.data) {
|
||||||
|
if (this.data.comments && this.entry && this.entry.id > 0 && this.commentsEnabled) {
|
||||||
|
promises.push(this.commentsProvider.invalidateCommentsData('module', this.data.coursemodule, 'mod_data',
|
||||||
|
this.entry.id, 'database_entry'));
|
||||||
|
}
|
||||||
promises.push(this.dataProvider.invalidateEntryData(this.data.id, this.entryId));
|
promises.push(this.dataProvider.invalidateEntryData(this.data.id, this.entryId));
|
||||||
promises.push(this.groupsProvider.invalidateActivityGroupInfo(this.data.coursemodule));
|
promises.push(this.groupsProvider.invalidateActivityGroupInfo(this.data.coursemodule));
|
||||||
promises.push(this.dataProvider.invalidateEntriesData(this.data.id));
|
promises.push(this.dataProvider.invalidateEntriesData(this.data.id));
|
||||||
|
|
|
@ -31,7 +31,6 @@ export class CoreCommentsCommentsComponent implements OnChanges, OnDestroy {
|
||||||
@Input() component: string;
|
@Input() component: string;
|
||||||
@Input() itemId: number;
|
@Input() itemId: number;
|
||||||
@Input() area = '';
|
@Input() area = '';
|
||||||
@Input() page = 0;
|
|
||||||
@Input() title?: string;
|
@Input() title?: string;
|
||||||
@Input() displaySpinner = true; // Whether to display the loading spinner.
|
@Input() displaySpinner = true; // Whether to display the loading spinner.
|
||||||
@Output() onLoading: EventEmitter<boolean>; // Eevent that indicates whether the component is loading data.
|
@Output() onLoading: EventEmitter<boolean>; // Eevent that indicates whether the component is loading data.
|
||||||
|
@ -72,7 +71,7 @@ export class CoreCommentsCommentsComponent implements OnChanges, OnDestroy {
|
||||||
*/
|
*/
|
||||||
ngOnChanges(changes: { [name: string]: SimpleChange }): void {
|
ngOnChanges(changes: { [name: string]: SimpleChange }): void {
|
||||||
// If something change, update the fields.
|
// If something change, update the fields.
|
||||||
if (changes) {
|
if (changes && this.commentsLoaded) {
|
||||||
this.fetchData();
|
this.fetchData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +107,6 @@ export class CoreCommentsCommentsComponent implements OnChanges, OnDestroy {
|
||||||
component: this.component,
|
component: this.component,
|
||||||
itemId: this.itemId,
|
itemId: this.itemId,
|
||||||
area: this.area,
|
area: this.area,
|
||||||
page: this.page,
|
|
||||||
title: this.title,
|
title: this.title,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,8 +51,8 @@ export class CoreCommentsViewerPage {
|
||||||
this.component = navParams.get('component');
|
this.component = navParams.get('component');
|
||||||
this.itemId = navParams.get('itemId');
|
this.itemId = navParams.get('itemId');
|
||||||
this.area = navParams.get('area') || '';
|
this.area = navParams.get('area') || '';
|
||||||
this.page = navParams.get('page') || 0;
|
|
||||||
this.title = navParams.get('title') || this.translate.instant('core.comments.comments');
|
this.title = navParams.get('title') || this.translate.instant('core.comments.comments');
|
||||||
|
this.page = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -76,12 +76,11 @@ export class CoreCommentsProvider {
|
||||||
* @param {string} component Component name.
|
* @param {string} component Component name.
|
||||||
* @param {number} itemId Associated id.
|
* @param {number} itemId Associated id.
|
||||||
* @param {string} [area=''] String comment area. Default empty.
|
* @param {string} [area=''] String comment area. Default empty.
|
||||||
* @param {number} [page=0] Page number (0 based). Default 0.
|
|
||||||
* @return {string} Cache key.
|
* @return {string} Cache key.
|
||||||
*/
|
*/
|
||||||
protected getCommentsCacheKey(contextLevel: string, instanceId: number, component: string,
|
protected getCommentsCacheKey(contextLevel: string, instanceId: number, component: string, itemId: number,
|
||||||
itemId: number, area: string = '', page: number = 0): string {
|
area: string = ''): string {
|
||||||
return this.getCommentsPrefixCacheKey(contextLevel, instanceId) + ':' + component + ':' + itemId + ':' + area + ':' + page;
|
return this.getCommentsPrefixCacheKey(contextLevel, instanceId) + ':' + component + ':' + itemId + ':' + area;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,8 +106,8 @@ export class CoreCommentsProvider {
|
||||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||||
* @return {Promise<any>} Promise resolved with the comments.
|
* @return {Promise<any>} Promise resolved with the comments.
|
||||||
*/
|
*/
|
||||||
getComments(contextLevel: string, instanceId: number, component: string, itemId: number,
|
getComments(contextLevel: string, instanceId: number, component: string, itemId: number, area: string = '', page: number = 0,
|
||||||
area: string = '', page: number = 0, siteId?: string): Promise<any> {
|
siteId?: string): Promise<any> {
|
||||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
const params: any = {
|
const params: any = {
|
||||||
contextlevel: contextLevel,
|
contextlevel: contextLevel,
|
||||||
|
@ -120,7 +119,7 @@ export class CoreCommentsProvider {
|
||||||
};
|
};
|
||||||
|
|
||||||
const preSets = {
|
const preSets = {
|
||||||
cacheKey: this.getCommentsCacheKey(contextLevel, instanceId, component, itemId, area, page),
|
cacheKey: this.getCommentsCacheKey(contextLevel, instanceId, component, itemId, area),
|
||||||
updateFrequency: CoreSite.FREQUENCY_SOMETIMES
|
updateFrequency: CoreSite.FREQUENCY_SOMETIMES
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -142,14 +141,17 @@ export class CoreCommentsProvider {
|
||||||
* @param {string} component Component name.
|
* @param {string} component Component name.
|
||||||
* @param {number} itemId Associated id.
|
* @param {number} itemId Associated id.
|
||||||
* @param {string} [area=''] String comment area. Default empty.
|
* @param {string} [area=''] String comment area. Default empty.
|
||||||
* @param {number} [page=0] Page number (0 based). Default 0.
|
|
||||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||||
* @return {Promise<any>} Promise resolved when the data is invalidated.
|
* @return {Promise<any>} Promise resolved when the data is invalidated.
|
||||||
*/
|
*/
|
||||||
invalidateCommentsData(contextLevel: string, instanceId: number, component: string, itemId: number,
|
invalidateCommentsData(contextLevel: string, instanceId: number, component: string, itemId: number,
|
||||||
area: string = '', page: number = 0, siteId?: string): Promise<any> {
|
area: string = '', siteId?: string): Promise<any> {
|
||||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
return site.invalidateWsCacheForKey(this.getCommentsCacheKey(contextLevel, instanceId, component, itemId, area, page));
|
// This is done with starting with to avoid conflicts with previous keys that were including page.
|
||||||
|
site.invalidateWsCacheForKeyStartingWith(this.getCommentsCacheKey(contextLevel, instanceId, component, itemId,
|
||||||
|
area) + ':');
|
||||||
|
|
||||||
|
return site.invalidateWsCacheForKey(this.getCommentsCacheKey(contextLevel, instanceId, component, itemId, area));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue