optional modules

This commit is contained in:
Pfeil, Scott Robert 2021-01-29 10:18:20 -05:00
parent d545af3278
commit 5cdb0414bb
3 changed files with 40 additions and 22 deletions

View File

@ -191,29 +191,32 @@
// Never use the cache.
completionHandler(nil,nil);
} else if (requestParameters.pageType.length != 0 && requestParameters.modules.count > 0) {
} else {
NSArray *modules = [requestParameters allModules];
if (requestParameters.pageType.length != 0 && modules.count > 0) {
// Check cache function for page json is already in the cache.
[[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
// Check cache function for page json is already in the cache.
[[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
// Check cache function for modules already in the cache.
NSDictionary *pageDictionary = jsonDictionary;
[[MVMCoreCache sharedCache] fetchJSONForModules:requestParameters.modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
completionHandler(pageDictionary,jsonDictionary);
// Check cache function for modules already in the cache.
NSDictionary *pageDictionary = jsonDictionary;
[[MVMCoreCache sharedCache] fetchJSONForModules:modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
completionHandler(pageDictionary,jsonDictionary);
}];
}];
}];
} else if (requestParameters.pageType.length != 0) {
} else if (requestParameters.pageType.length != 0) {
// Check cache function if page json is already in the cache.
[[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
completionHandler(jsonDictionary,nil);
}];
} else if (requestParameters.modules.count > 0) {
// Check cache function if modules already in the cache.
[[MVMCoreCache sharedCache] fetchJSONForModules:requestParameters.modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
completionHandler(nil,jsonDictionary);
}];
// Check cache function if page json is already in the cache.
[[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
completionHandler(jsonDictionary,nil);
}];
} else if (modules > 0) {
// Check cache function if modules already in the cache.
[[MVMCoreCache sharedCache] fetchJSONForModules:modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
completionHandler(nil,jsonDictionary);
}];
}
}
}
@ -239,16 +242,21 @@
// Check if the page was found in the cache.
BOOL pageNotInCache = loadObject.operation.requestParameters.pageType && !loadObject.pageDataFromCache;
// Check all modules were found in the cache
// Check all required modules were found in the cache
NSMutableArray *modulesNotInCache = [NSMutableArray array];
for (NSString *module in loadObject.operation.requestParameters.modules) {
NSMutableArray *requiredModules = [NSMutableArray arrayWithArray:loadObject.operation.requestParameters.modules];
for (NSString *module in [loadObject.operation.requestParameters allModules]) {
if (![loadObject.modulesJSON objectForKey:module]) {
// Missing a module.
[modulesNotInCache addObject:module];
} else {
// Received a required module.
[requiredModules removeObject:module];
}
}
MVMCoreRequestParameters *requestParametersForServer = nil;
if (pageNotInCache || modulesNotInCache.count > 0) {
if (pageNotInCache || requiredModules.count > 0) {
// We are missing data, will need to go to server.
requestParametersForServer = [loadObject.operation.requestParameters copy];

View File

@ -29,6 +29,7 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) {
// request parameters
@property (nullable, strong, nonatomic) NSString *pageType;
@property (nullable, strong, nonatomic) NSArray *optionalModules;
@property (nullable, strong, nonatomic) NSArray *modules;
@property (nullable, strong, nonatomic) NSDictionary *parameters;
@property (nullable, strong, nonatomic) NSData *imageData;
@ -120,4 +121,7 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) {
// Sets the load style based on the server sent presentationStyle
- (void)setMFLoadStyleBasedOnPresentationStyle:(nonnull NSString *)presentationStyle;
/// Returns optional and required modules
- (nullable NSArray *)allModules;
@end

View File

@ -116,6 +116,12 @@
}
}
- (nullable NSArray *)allModules {
NSMutableSet *set = [NSMutableSet setWithArray:self.optionalModules];
[set addObjectsFromArray:self.modules];
return [set allObjects];
}
- (id)copyWithZone:(nullable NSZone *)zone {
MVMCoreRequestParameters *copyObject = [[MVMCoreRequestParameters alloc] init];