Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS-586 Implement logic to add expiration date to banned books and remove expired banned books #1627

Merged
merged 7 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Simplified.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2556,8 +2556,8 @@
73FB0AC824EB403D0072E430 /* NYPLBookContentTypeConverter.swift */,
1139DA6319C7755D00A07810 /* NYPLBookCoverRegistry.h */,
1139DA6419C7755D00A07810 /* NYPLBookCoverRegistry.m */,
1164F104199AC236009BF8BF /* NYPLBookLocation.h */,
1164F105199AC236009BF8BF /* NYPLBookLocation.m */,
1164F104199AC236009BF8BF /* NYPLBookLocation.h */,
11616E0F196B0531003D60D9 /* NYPLBookRegistry.h */,
11616E10196B0531003D60D9 /* NYPLBookRegistry.m */,
112C694B197301FE00C48F95 /* NYPLBookRegistryRecord.h */,
Expand Down Expand Up @@ -4706,7 +4706,7 @@
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES_ERROR;
CODE_SIGN_ENTITLEMENTS = Simplified/SimplyE.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 0;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = 7262U6ST2R;
ENABLE_BITCODE = NO;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
Expand Down Expand Up @@ -4754,7 +4754,7 @@
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES_ERROR;
CODE_SIGN_ENTITLEMENTS = Simplified/SimplyE.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CURRENT_PROJECT_VERSION = 0;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = 7262U6ST2R;
ENABLE_BITCODE = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand Down Expand Up @@ -5014,7 +5014,7 @@
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES_ERROR;
CODE_SIGN_ENTITLEMENTS = Simplified/SimplyE.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 0;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = 7262U6ST2R;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand Down Expand Up @@ -5064,7 +5064,7 @@
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES_ERROR;
CODE_SIGN_ENTITLEMENTS = Simplified/SimplyE.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CURRENT_PROJECT_VERSION = 0;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = 7262U6ST2R;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Simplified/AppInfrastructure/Simplified-Prefix.pch";
Expand Down
5 changes: 5 additions & 0 deletions Simplified/Book/Models/NYPLBook.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,9 @@
/// @return The default NYPLBookContentType
- (NYPLBookContentType)defaultBookContentType;

/// Add a custom expiration date to book if
/// 1. book is distributed by Axis360
/// 2. book does not contain an expiration date
- (void)addCustomExpirateDate:(nonnull NSDate *)date;
ettore marked this conversation as resolved.
Show resolved Hide resolved

@end
15 changes: 15 additions & 0 deletions Simplified/Book/Models/NYPLBook.m
Original file line number Diff line number Diff line change
Expand Up @@ -618,4 +618,19 @@ - (NYPLBookContentType)defaultBookContentType
return defaultType;
}

- (void)addCustomExpirateDate:(nonnull NSDate *)date
{
if (self.defaultAcquisitionIfOpenAccess.type &&
ettore marked this conversation as resolved.
Show resolved Hide resolved
[self.defaultAcquisitionIfOpenAccess.type isEqualToString:ContentTypeAxis360] &&
!self.defaultAcquisitionIfOpenAccess.availability.until)
{
NYPLOPDSAcquisitionAvailabilityLimited *currentAvailability = (NYPLOPDSAcquisitionAvailabilityLimited *)self.defaultAcquisition.availability;
NYPLOPDSAcquisitionAvailabilityLimited *newAvailability = [[NYPLOPDSAcquisitionAvailabilityLimited alloc]
initWithCopiesAvailable:currentAvailability.copiesAvailable
copiesTotal:currentAvailability.copiesTotal
since:currentAvailability.since
until:date];
[self.defaultAcquisition updateAvailability:newAvailability];
}
}
@end
6 changes: 6 additions & 0 deletions Simplified/Book/Models/NYPLBookRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ typedef NS_ENUM(NSInteger, NYPLBookState);
*/
- (void)syncWithStandardAlertsOnCompletion;

/**
Goes through all books in registry and remove the expired books distributed by Axis 360.
@note: Only call this function if the library does not require authentication
*/
- (void)removeExpiredBooksWithoutFeed;
ettore marked this conversation as resolved.
Show resolved Hide resolved

// Adds a book to the book registry until it is manually removed. It allows the application to
// present information about obtained books when offline. Attempting to add a book already present
// will overwrite the existing book as if |updateBook:| were called. The location may be nil. The
Expand Down
23 changes: 23 additions & 0 deletions Simplified/Book/Models/NYPLBookRegistry.m
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,29 @@ - (void)syncWithStandardAlertsOnCompletion
}];
}

- (void)removeExpiredBooksWithoutFeed
{
@synchronized(self) {
NSMutableArray *booksToRemove = [[NSMutableArray alloc] init];
for (NSString *bookIdentifer in self.identifiersToRecords) {
NYPLBookRegistryRecord *record = self.identifiersToRecords[bookIdentifer];
// Add the book to remove list if it is distributed by Axis360 and expired
if(record &&
record.book.defaultAcquisition.type &&
ettore marked this conversation as resolved.
Show resolved Hide resolved
[record.book.defaultAcquisition.type isEqualToString:ContentTypeAxis360]) {
if (record.book.defaultAcquisition.availability.until &&
[record.book.defaultAcquisition.availability.until compare:[NSDate date]] == NSOrderedAscending) {
[booksToRemove addObject:bookIdentifer];
}
}
}
for (NSString *bookIdentifier in booksToRemove) {
[self removeBookForIdentifier:bookIdentifier];
}
[self save];
}
}

- (void)addBook:(NYPLBook *const)book
location:(NYPLBookLocation *const)location
state:(NSInteger)state
Expand Down
3 changes: 3 additions & 0 deletions Simplified/Catalog/NYPLCatalogFeedViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ - (void)viewDidLoad
}

[[NYPLBookRegistry sharedRegistry] justLoad];
if (!NYPLUserAccount.sharedAccount.requiresUserAuthentication) {
[[NYPLBookRegistry sharedRegistry] removeExpiredBooksWithoutFeed];
}
UIApplicationState applicationState = [[UIApplication sharedApplication] applicationState];
if (applicationState == UIApplicationStateActive) {
[self syncBookRegistryForNewFeed];
Expand Down
13 changes: 13 additions & 0 deletions Simplified/Catalog/NYPLCatalogGroupedFeed.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ - (instancetype)initWithOPDSFeed:(NYPLOPDSFeed *)feed
NSMutableDictionary *const groupTitleToMutableBookArray = [NSMutableDictionary dictionary];
NSMutableDictionary *const groupTitleToURLOrNull = [NSMutableDictionary dictionary];

// Create an expiration date object with value of 2 months from now
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
ettore marked this conversation as resolved.
Show resolved Hide resolved
[dateComponents setMonth:2];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *expirationDate = [calendar dateByAddingComponents:dateComponents toDate:[NSDate new] options:0];

for(NYPLOPDSEntry *const entry in feed.entries) {
if(!entry.groupAttributes) {
NYPLLOG(@"Ignoring entry with missing group.");
Expand All @@ -110,6 +116,13 @@ - (instancetype)initWithOPDSFeed:(NYPLOPDSFeed *)feed
continue;
}

/// Add a custom expiration date (2 months from now) to banned book.
/// This expiration date will be overwritten by the updatedBookMetadata function below
/// if the book is already checked out.
if (!NYPLUserAccount.sharedAccount.requiresUserAuthentication) {
[book addCustomExpirateDate:expirationDate];
}

NYPLBook *updatedBook = [[NYPLBookRegistry sharedRegistry] updatedBookMetadata:book];
if(updatedBook) {
book = updatedBook;
Expand Down
13 changes: 13 additions & 0 deletions Simplified/Catalog/NYPLCatalogUngroupedFeed.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ - (instancetype)initWithOPDSFeed:(NYPLOPDSFeed *const)feed

self.books = [NSMutableArray array];

// Create an expiration date object with value of 2 months from now
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setMonth:2];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *expirationDate = [calendar dateByAddingComponents:dateComponents toDate:[NSDate new] options:0];

for(NYPLOPDSEntry *const entry in feed.entries) {
NYPLBook *book = [NYPLBook bookWithEntry:entry];
if(!book) {
Expand All @@ -50,6 +56,13 @@ - (instancetype)initWithOPDSFeed:(NYPLOPDSFeed *const)feed
continue;
}

/// Add a custom expiration date (2 months from now) to banned book.
/// This expiration date will be overwritten by the updatedBookMetadata function below
/// if the book is already checked out.
if (!NYPLUserAccount.sharedAccount.requiresUserAuthentication) {
[book addCustomExpirateDate:expirationDate];
}

NYPLBook *updatedBook = [[NYPLBookRegistry sharedRegistry] updatedBookMetadata:book];
if(updatedBook) {
book = updatedBook;
Expand Down
2 changes: 2 additions & 0 deletions Simplified/OPDS/NYPLOPDSAcquisition.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ NYPLOPDSAcquisitionRelationString(NYPLOPDSAcquisitionRelation relation);
/// @c acquisitionWithDictionary: method for later deserialization.
- (NSDictionary *_Nonnull)dictionaryRepresentation;

- (void)updateAvailability:(id<NYPLOPDSAcquisitionAvailability> _Nonnull)availability;
ettore marked this conversation as resolved.
Show resolved Hide resolved

@end
4 changes: 4 additions & 0 deletions Simplified/OPDS/NYPLOPDSAcquisition.m
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,8 @@ - (NSDictionary *_Nonnull)dictionaryRepresentation
};
}

- (void)updateAvailability:(id<NYPLOPDSAcquisitionAvailability> _Nonnull)availability {
self.availability = availability;
}

@end
12 changes: 7 additions & 5 deletions scripts/firebase-upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ else
fatal "Unable to upload to firebase: missing ad-hoc export!"
fi

# Disabling the IPA upload to firebase because we encountered authentication error,
# possibly due to `token` authentication is deprecated.
# upload app binary
echo "Using ipa at $IPA_PATH"
firebase appdistribution:distribute \
--token "${FIREBASE_TOKEN}" \
--app "${FIREBASE_APP_ID}" \
"${IPA_PATH}"
#echo "Using ipa at $IPA_PATH"
#firebase appdistribution:distribute \
# --token "${FIREBASE_TOKEN}" \
# --app "${FIREBASE_APP_ID}" \
# "${IPA_PATH}"

# upload symbols
./scripts/firebase-upload-symbols.sh "$APPNAME_PARAM" "$DSYMS_PATH"
Expand Down
Loading