Skip to content

Commit

Permalink
Merge pull request #5157 from wikimedia/fix-saved-slide-crash
Browse files Browse the repository at this point in the history
[YiR] Fixed saved articles slide crash
  • Loading branch information
tonisevener authored Jan 17, 2025
2 parents 48a44cf + f917ee4 commit ece490c
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ContinueReadingWidget/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>7.6.3</string>
<string>7.6.4</string>
<key>CFBundleVersion</key>
<string>0</string>
<key>NSExtension</key>
Expand Down
2 changes: 1 addition & 1 deletion NotificationServiceExtension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>7.6.3</string>
<string>7.6.4</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSExtension</key>
Expand Down
2 changes: 1 addition & 1 deletion WMF Framework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>7.6.3</string>
<string>7.6.4</string>
<key>CFBundleVersion</key>
<string>0</string>
<key>NSPrincipalClass</key>
Expand Down
2 changes: 1 addition & 1 deletion Widgets/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>7.6.3</string>
<string>7.6.4</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSExtension</key>
Expand Down
2 changes: 1 addition & 1 deletion Wikipedia Stickers/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>7.6.3</string>
<string>7.6.4</string>
<key>CFBundleVersion</key>
<string>0</string>
<key>UIRequiredDeviceCapabilities</key>
Expand Down
20 changes: 14 additions & 6 deletions Wikipedia/Code/MWKSavedPageList.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ - (NSFetchRequest *)savedPageListFetchRequest {
return request;
}

- (NSFetchRequest *)savedPageListFetchRequestForStartDate:(NSDate *)startDate endDate:(NSDate *)endDate {
- (NSFetchRequest *)savedPageListFetchRequestForStartDate:(NSDate *)startDate endDate:(NSDate *)endDate filterNilDisplayTitles:(BOOL)filterNilDisplayTitles {
NSFetchRequest *request = [WMFArticle fetchRequest];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"savedDate >= %@ AND savedDate <= %@", startDate, endDate];

if (filterNilDisplayTitles) {
predicate = [NSPredicate predicateWithFormat:@"savedDate >= %@ AND savedDate <= %@ AND displayTitle != nil", startDate, endDate];
}

request.predicate = predicate;
request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"savedDate" ascending:NO]];
return request;
Expand Down Expand Up @@ -152,11 +157,11 @@ - (void)removeEntryWithURL:(NSURL *)url {
}

- (NSInteger)savedArticleCountFor:(NSDate *)startDate endDate:(NSDate *)endDate {
return [self.dataStore.viewContext countForFetchRequest:[self savedPageListFetchRequestForStartDate:startDate endDate:endDate] error:nil];
return [self.dataStore.viewContext countForFetchRequest:[self savedPageListFetchRequestForStartDate:startDate endDate:endDate filterNilDisplayTitles:NO] error:nil];
}

- (NSArray<NSString *> *)randomSavedArticleTitlesFor:(NSDate *)startDate endDate:(NSDate *)endDate {
NSFetchRequest *fetchRequest = [self savedPageListFetchRequestForStartDate:startDate endDate:endDate];
NSFetchRequest *fetchRequest = [self savedPageListFetchRequestForStartDate:startDate endDate:endDate filterNilDisplayTitles:YES];

NSError *error = nil;
NSArray<WMFArticle *> *allArticles = [self.dataStore.viewContext executeFetchRequest:fetchRequest error:&error];
Expand All @@ -176,12 +181,15 @@ - (NSInteger)savedArticleCountFor:(NSDate *)startDate endDate:(NSDate *)endDate

for (NSUInteger i = 0; i < count; i++) {
NSUInteger randomIndex = arc4random_uniform((uint32_t)mutableArticles.count);
[randomArticles addObject:mutableArticles[randomIndex].displayTitle];
[mutableArticles removeObjectAtIndex:randomIndex]; // so we do not repeat articles
if (mutableArticles[randomIndex].displayTitle != nil) {
[randomArticles addObject:mutableArticles[randomIndex].displayTitle];
[mutableArticles removeObjectAtIndex:randomIndex]; // so we do not repeat articles
} else {
continue;
}
}

return [randomArticles copy];
}


@end
2 changes: 1 addition & 1 deletion Wikipedia/Experimental-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>7.6.3</string>
<string>7.6.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down
2 changes: 1 addition & 1 deletion Wikipedia/Local-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>7.6.3</string>
<string>7.6.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down
2 changes: 1 addition & 1 deletion Wikipedia/Staging-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>7.6.3</string>
<string>7.6.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down
2 changes: 1 addition & 1 deletion Wikipedia/Wikipedia-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>7.6.3</string>
<string>7.6.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down
2 changes: 1 addition & 1 deletion WikipediaUnitTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>7.6.3</string>
<string>7.6.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down

0 comments on commit ece490c

Please sign in to comment.