MOBILE-4117 bbb: Update Moodle cache when needed

main
Dani Palou 2022-09-05 11:06:17 +02:00
parent 2f02aaf149
commit 7b59283420
2 changed files with 26 additions and 6 deletions

View File

@ -17,6 +17,7 @@ import { CoreError } from '@classes/errors/error';
import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component';
import { CoreCourseContentsPage } from '@features/course/pages/contents/contents';
import { IonContent } from '@ionic/angular';
import { CoreApp } from '@services/app';
import { CoreGroupInfo, CoreGroups } from '@services/groups';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils';
@ -79,9 +80,10 @@ export class AddonModBBBIndexComponent extends CoreCourseModuleMainActivityCompo
/**
* Get meeting info.
*
* @param updateCache Whether to update info cached data (in server).
* @return Promise resolved when done.
*/
async fetchMeetingInfo(): Promise<void> {
async fetchMeetingInfo(updateCache?: boolean): Promise<void> {
if (!this.bbb) {
return;
}
@ -89,6 +91,7 @@ export class AddonModBBBIndexComponent extends CoreCourseModuleMainActivityCompo
try {
this.meetingInfo = await AddonModBBB.getMeetingInfo(this.bbb.id, this.groupId, {
cmId: this.module.id,
updateCache,
});
if (this.meetingInfo.statusrunning && this.meetingInfo.userlimit > 0) {
@ -120,9 +123,10 @@ export class AddonModBBBIndexComponent extends CoreCourseModuleMainActivityCompo
/**
* Update meeting info.
*
* @param updateCache Whether to update info cached data (in server).
* @return Promise resolved when done.
*/
async updateMeetingInfo(): Promise<void> {
async updateMeetingInfo(updateCache?: boolean): Promise<void> {
if (!this.bbb) {
return;
}
@ -132,7 +136,7 @@ export class AddonModBBBIndexComponent extends CoreCourseModuleMainActivityCompo
try {
await AddonModBBB.invalidateAllGroupsMeetingInfo(this.bbb.id);
await this.fetchMeetingInfo();
await this.fetchMeetingInfo(updateCache);
} finally {
this.showLoading = false;
}
@ -182,11 +186,14 @@ export class AddonModBBBIndexComponent extends CoreCourseModuleMainActivityCompo
try {
const joinUrl = await AddonModBBB.getJoinUrl(this.module.id, this.groupId);
CoreUtils.openInBrowser(joinUrl, {
await CoreUtils.openInBrowser(joinUrl, {
showBrowserWarning: false,
});
this.updateMeetingInfo();
// Leave some time for the room to load.
await CoreApp.waitForResume(10000);
this.updateMeetingInfo(true);
} catch (error) {
CoreDomUtils.showErrorModal(error);
} finally {

View File

@ -151,7 +151,7 @@ export class AddonModBBBService {
async getMeetingInfo(
id: number,
groupId: number = 0,
options: CoreCourseCommonModWSOptions = {},
options: AddonModBBBGetMeetingInfoOptions = {},
): Promise<AddonModBBBMeetingInfoWSResponse> {
const site = await CoreSites.getSite(options.siteId);
@ -161,10 +161,16 @@ export class AddonModBBBService {
};
const preSets: CoreSiteWSPreSets = {
cacheKey: this.getMeetingInfoCacheKey(id, groupId),
getCacheUsingCacheKey: true,
uniqueCacheKey: true,
component: AddonModBBBService.COMPONENT,
componentId: options.cmId,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
};
if (options.updateCache) {
params.updatecache = true;
preSets.getFromCache = false;
}
return site.read<AddonModBBBMeetingInfoWSResponse>(
'mod_bigbluebuttonbn_meeting_info',
@ -380,3 +386,10 @@ export type AddonModBBBEndMeetingWSParams = {
bigbluebuttonbnid: number; // Bigbluebuttonbn instance id.
groupid?: number; // Bigbluebuttonbn group id.
};
/**
* Options for getMeetingInfo.
*/
export type AddonModBBBGetMeetingInfoOptions = CoreCourseCommonModWSOptions & {
updateCache?: boolean;
};