Skip to content

Commit

Permalink
Merge branch 'release/simplye-v3.8.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
ettore committed Feb 10, 2022
2 parents 407df6c + c6080f2 commit 28fb17f
Show file tree
Hide file tree
Showing 39 changed files with 1,734 additions and 377 deletions.
2 changes: 1 addition & 1 deletion Axis-iOS
2 changes: 1 addition & 1 deletion Certificates
150 changes: 140 additions & 10 deletions Simplified.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repositoryURL": "https://github.com/NYPL-Simplified/iOS-Utilities",
"state": {
"branch": "main",
"revision": "dda470221a5e6eca49e1acef8bd2c08bebbeebe1",
"revision": "ba9e5e8e511bf6f2acc1c4f9262ff5e405bfcb1d",
"version": null
}
},
Expand Down
14 changes: 0 additions & 14 deletions Simplified.xcodeproj/xcshareddata/xcschemes/Open eBooks.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,6 @@
ReferencedContainer = "container:Simplified.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "NO"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NYPLAxisTests"
BuildableName = "NYPLAxisTests"
BlueprintName = "NYPLAxisTests"
ReferencedContainer = "container:Axis-iOS">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down
4 changes: 1 addition & 3 deletions Simplified/Accounts/Library/AccountsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ let currentAccountIdentifierKey = "NYPLCurrentAccountIdentifier"
var mainFeed = URL(string: self.currentAccount?.catalogUrl ?? "")
let resolveFn = {
Log.debug(#function, "mainFeedURL=\(String(describing: mainFeed))")
NYPLSettings.shared.accountMainFeedURL = mainFeed
UIApplication.shared.delegate?.window??.tintColor = NYPLConfiguration.mainColor()
NotificationCenter.default.post(name: NSNotification.Name.NYPLCurrentAccountDidChange, object: nil)
NYPLSettings.shared.updateMainFeedURLIfNeeded(with: mainFeed)
completion(true)
}

Expand Down
11 changes: 10 additions & 1 deletion Simplified/AxisService/Download/NYPLAxisDRMAuthorizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ class NYPLAxisDRMAuthorizer: NSObject, NYPLDRMAuthorizing {
return true
}

/// As of now, we're creating a deviceID which stays saved until the user uninstalls the app.
/// Creates a deviceID which stays saved until the user uninstalls the app.
///
/// - Note: the parameters of this function are implicit unwrapped optionals
/// to match the signature of an ObjC api for another DRM authorizer.
///
/// - Parameters:
/// - vendorID: Ignored.
/// - username: Must not be nil.
/// - password: Ignored.
/// - completion: Must not be nil.
func authorize(withVendorID vendorID: String!,
username: String!,
password: String!,
Expand Down
6 changes: 5 additions & 1 deletion Simplified/AxisService/Read/NYPLAxisBookReadingAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ struct NYPLAxisBookReadingAdapter {
licenseService.extractAESKey { result in
switch result {
case .success(let key):
guard let keyData = key else {
completion(.success(nil))
return
}
let protectedAsset = self.getProtectedAsset(
from: asset, key: key, fetcher: fetcher)
from: asset, key: keyData, fetcher: fetcher)
completion(.success(protectedAsset))
case .failure(let error):
completion(.failure(.forbidden(error)))
Expand Down
178 changes: 89 additions & 89 deletions Simplified/Book/Models/NYPLBookRegistry.m
Original file line number Diff line number Diff line change
Expand Up @@ -310,98 +310,98 @@ - (void)syncResettingCache:(BOOL)shouldResetCache
[self broadcastChange];
} //@synchronized

[NYPLOPDSFeed
withURL:[[[AccountsManager sharedInstance] currentAccount] loansUrl]
shouldResetCache:shouldResetCache
completionHandler:^(NYPLOPDSFeed *const feed, NSDictionary *error) {
if(!feed) {
NYPLLOG(@"Failed to obtain sync data.");
self.syncing = NO;
[self broadcastChange];
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
if(completion) completion(error);
if(fetchHandler) fetchHandler(UIBackgroundFetchResultFailed);
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification.NYPLSyncEnded object:nil];
}];
[NYPLErrorLogger logErrorWithCode:NYPLErrorCodeApiCall
summary:@"Unable to fetch loans"
metadata:@{
@"shouldResetCache": @(shouldResetCache),
@"errorDict": error ?: @"N/A"
}];
return;
}
[NYPLOPDSFeedFetcher fetchOPDSFeedWithUrl:[[[AccountsManager sharedInstance] currentAccount] loansUrl]
networkExecutor:[NYPLNetworkExecutor shared]
shouldResetCache:shouldResetCache
completion:^(NYPLOPDSFeed * _Nullable feed, NSDictionary<NSString *,id> * _Nullable errorDict) {
if(!feed) {
NYPLLOG(@"Failed to obtain sync data.");
self.syncing = NO;
[self broadcastChange];
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
if(completion) completion(errorDict);
if(fetchHandler) fetchHandler(UIBackgroundFetchResultFailed);
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification.NYPLSyncEnded object:nil];
}];
[NYPLErrorLogger logErrorWithCode:NYPLErrorCodeApiCall
summary:@"Unable to fetch loans"
metadata:@{
@"shouldResetCache": @(shouldResetCache),
@"errorDict": errorDict ?: @"N/A"
}];
return;
}

[NYPLErrorLogger setUserID:[[NYPLUserAccount sharedAccount] barcode]];

if(!self.syncShouldCommit) {
NYPLLOG(@"[syncWithCompletionHandler] Sync shouldn't commit");
// A reset must have occurred.
self.syncing = NO;
[self broadcastChange];
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
if(fetchHandler) fetchHandler(UIBackgroundFetchResultNoData);
}];
return;
}

void (^commitBlock)(void) = ^void() {
[self performSynchronizedWithoutBroadcasting:^{

if (feed.licensor) {
[[NYPLUserAccount sharedAccount] setLicensor:feed.licensor];
NYPLLOG_F(@"\nLicensor Token Updated: %@\nFor account: %@",feed.licensor[@"clientToken"],[NYPLUserAccount sharedAccount].userID);
} else {
NYPLLOG(@"A Licensor Token was not received or parsed from the OPDS feed.");
}

NSMutableSet *identifiersToRemove = [NSMutableSet setWithArray:self.identifiersToRecords.allKeys];
for(NYPLOPDSEntry *const entry in feed.entries) {
NYPLBook *const book = [NYPLBook bookWithEntry:entry];
if(!book) {
NYPLLOG_F(@"Failed to create book for entry '%@'.", entry.identifier);
continue;
}
[identifiersToRemove removeObject:book.identifier];
NYPLBook *const existingBook = [self bookForIdentifier:book.identifier];
if(existingBook) {
[self updateBook:book];
} else {
[self addBook:book location:nil state:NYPLBookStateDownloadNeeded fulfillmentId:nil readiumBookmarks:nil genericBookmarks:nil];
}
}
for (NSString *identifier in identifiersToRemove) {
NYPLBookRegistryRecord *record = [self.identifiersToRecords objectForKey:identifier];
if (record && (record.state == NYPLBookStateDownloadSuccessful || record.state == NYPLBookStateUsed)) {
[[NYPLMyBooksDownloadCenter sharedDownloadCenter] deleteLocalContentForBookIdentifier:identifier];
}
[self removeBookForIdentifier:identifier];
}

if(!self.syncShouldCommit) {
NYPLLOG(@"[syncWithCompletionHandler] Sync shouldn't commit");
// A reset must have occurred.
self.syncing = NO;
[self broadcastChange];
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
if(fetchHandler) fetchHandler(UIBackgroundFetchResultNoData);
}];
return;
}

void (^commitBlock)(void) = ^void() {
[self performSynchronizedWithoutBroadcasting:^{

if (feed.licensor) {
[[NYPLUserAccount sharedAccount] setLicensor:feed.licensor];
NYPLLOG_F(@"\nLicensor Token Updated: %@\nFor account: %@",feed.licensor[@"clientToken"],[NYPLUserAccount sharedAccount].userID);
} else {
NYPLLOG(@"A Licensor Token was not received or parsed from the OPDS feed.");
}

NSMutableSet *identifiersToRemove = [NSMutableSet setWithArray:self.identifiersToRecords.allKeys];
for(NYPLOPDSEntry *const entry in feed.entries) {
NYPLBook *const book = [NYPLBook bookWithEntry:entry];
if(!book) {
NYPLLOG_F(@"Failed to create book for entry '%@'.", entry.identifier);
continue;
}
[identifiersToRemove removeObject:book.identifier];
NYPLBook *const existingBook = [self bookForIdentifier:book.identifier];
if(existingBook) {
[self updateBook:book];
} else {
[self addBook:book location:nil state:NYPLBookStateDownloadNeeded fulfillmentId:nil readiumBookmarks:nil genericBookmarks:nil];
}
}
for (NSString *identifier in identifiersToRemove) {
NYPLBookRegistryRecord *record = [self.identifiersToRecords objectForKey:identifier];
if (record && (record.state == NYPLBookStateDownloadSuccessful || record.state == NYPLBookStateUsed)) {
[[NYPLMyBooksDownloadCenter sharedDownloadCenter] deleteLocalContentForBookIdentifier:identifier];
}
[self removeBookForIdentifier:identifier];
}
}];
self.syncing = NO;
[self broadcastChange];
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
[NYPLUserNotifications updateAppIconBadgeWithHeldBooks:[self heldBooks]];
if(completion) completion(nil);
if(fetchHandler) fetchHandler(UIBackgroundFetchResultNewData);
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification.NYPLSyncEnded object:nil];
}];
self.syncing = NO;
[self broadcastChange];
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
[NYPLUserNotifications updateAppIconBadgeWithHeldBooks:[self heldBooks]];
if(completion) completion(nil);
if(fetchHandler) fetchHandler(UIBackgroundFetchResultNewData);
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification.NYPLSyncEnded object:nil];
}];
};

if (self.delaySync) {
if (self.delayedSyncBlock) {
NYPLLOG(@"[syncWithCompletionHandler] Delaying sync; block already exists!");
} else {
NYPLLOG(@"[syncWithCompletionHandler] Delaying sync");
}
self.delayedSyncBlock = commitBlock;
} else {
commitBlock();
}
}];
};

if (self.delaySync) {
if (self.delayedSyncBlock) {
NYPLLOG(@"[syncWithCompletionHandler] Delaying sync; block already exists!");
} else {
NYPLLOG(@"[syncWithCompletionHandler] Delaying sync");
}
self.delayedSyncBlock = commitBlock;
} else {
commitBlock();
}
}];
}

- (void)syncWithStandardAlertsOnCompletion
Expand Down
4 changes: 3 additions & 1 deletion Simplified/Book/UI/NYPLBookDetailTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ private let standardCellHeight: CGFloat = 44.0
}

addPendingIndicator()
NYPLOPDSFeed.withURL(url, shouldResetCache: false) { (feed, errorDict) in
NYPLOPDSFeedFetcher.fetchOPDSFeed(url: url,
networkExecutor: NYPLNetworkExecutor.shared,
shouldResetCache: false) { feed, errorDict in
DispatchQueue.main.async {
if feed?.type == .acquisitionGrouped {
let groupedFeed = NYPLCatalogGroupedFeed.init(opdsFeed: feed)
Expand Down
Loading

0 comments on commit 28fb17f

Please sign in to comment.