Fix: keep unread state if open unread articles failed

This commit is contained in:
relikd
2019-07-23 15:49:45 +02:00
parent 666ecd154f
commit 85cc12f34a
6 changed files with 30 additions and 22 deletions

View File

@@ -17,6 +17,7 @@ and this project does NOT adhere to [Semantic Versioning](https://semver.org/spe
- Changed error message text when user cancels creation of new feed item
- Comparing existing articles with nonexistent guid and link
- Adding feed: If URLs can't be resolved in the first run (5xx error), try a second time. E.g., 'Done' click (issue: #5)
- Don't mark articles read if opening URLs failed
### Changed
- Interface builder files replaced with code equivalent

View File

@@ -80,15 +80,16 @@
NSManagedObjectContext *moc = [StoreCoordinator createChildContext];
FeedArticle *fa = [moc objectWithID:sender.representedObject];
NSString *url = fa.link;
if (flipUnread || fa.unread) {
BOOL success = NO;
if (url && url.length > 0 && !flipUnread) // flipUnread == change unread state
success = [UserPrefs openURLsWithPreferredBrowser:@[[NSURL URLWithString:url]]];
if (flipUnread || (success && fa.unread)) {
fa.unread = !fa.unread;
NSNumber *num = (fa.unread ? @+1 : @-1);
[StoreCoordinator saveContext:moc andParent:YES];
NSNumber *num = (fa.unread ? @+1 : @-1);
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationTotalUnreadCountChanged object:num];
}
[moc reset];
if (url && url.length > 0 && !flipUnread) // flipUnread == change unread state
[UserPrefs openURLsWithPreferredBrowser:@[[NSURL URLWithString:url]]];
}
@end

View File

@@ -89,7 +89,7 @@
self.warningText = txt;
// Reload button is only visible on 5xx server error (right of )
self.warningReload = [[[[NSView buttonIcon:NSImageNameRefreshTemplate size:16] placeIn:content x:35 yTop:21]
tooltip:NSLocalizedString(@"Retry download (Cmd+R)", nil)]
tooltip:NSLocalizedString(@"Retry download (R)", nil)]
action:@selector(reloadData) target:nil]; // up the responder chain
}

View File

@@ -28,7 +28,7 @@
+ (NSString*)getHttpApplication;
+ (void)setHttpApplication:(NSString*)bundleID;
+ (void)openURLsWithPreferredBrowser:(NSArray<NSURL*>*)urls;
+ (BOOL)openURLsWithPreferredBrowser:(NSArray<NSURL*>*)urls;
+ (NSUInteger)openFewLinksLimit; // Change with: 'defaults write de.relikd.baRSS openFewLinksLimit -int 10'
+ (NSUInteger)shortArticleNamesLimit; // Change with: 'defaults write de.relikd.baRSS shortArticleNamesLimit -int 50'

View File

@@ -59,10 +59,11 @@
Open web links in default browser or a browser the user selected in the preferences.
@param urls A list of @c NSURL objects that will be opened immediatelly in bulk.
@return @c YES if @c urls are opened successfully. @c NO on error.
*/
+ (void)openURLsWithPreferredBrowser:(NSArray<NSURL*>*)urls {
if (urls.count == 0) return;
[[NSWorkspace sharedWorkspace] openURLs:urls withAppBundleIdentifier:[self getHttpApplication] options:NSWorkspaceLaunchDefault additionalEventParamDescriptor:nil launchIdentifiers:nil];
+ (BOOL)openURLsWithPreferredBrowser:(NSArray<NSURL*>*)urls {
if (urls.count == 0) return NO;
return [[NSWorkspace sharedWorkspace] openURLs:urls withAppBundleIdentifier:[self getHttpApplication] options:NSWorkspaceLaunchDefault additionalEventParamDescriptor:nil launchIdentifiers:nil];
}
#pragma mark - Hidden Plist Properties -

View File

@@ -193,20 +193,25 @@ typedef NS_ENUM(NSInteger, MenuItemTag) {
NSManagedObjectContext *moc = [StoreCoordinator createChildContext];
NSArray<FeedArticle*> *list = [StoreCoordinator articlesAtPath:path isFeed:isFeedMenu sorted:openLinks unread:markRead inContext:moc limit:limit];
NSNumber *countDiff = [NSNumber numberWithUnsignedInteger:list.count];
if (markRead) countDiff = [NSNumber numberWithInteger: -1 * countDiff.integerValue];
NSMutableArray<NSURL*> *urls = [NSMutableArray arrayWithCapacity:list.count];
for (FeedArticle *fa in list) {
fa.unread = !markRead;
if (openLinks && fa.link.length > 0)
[urls addObject:[NSURL URLWithString:fa.link]];
BOOL success = NO;
if (openLinks) {
NSMutableArray<NSURL*> *urls = [NSMutableArray arrayWithCapacity:list.count];
for (FeedArticle *fa in list) {
if (fa.link.length > 0)
[urls addObject:[NSURL URLWithString:fa.link]];
}
success = [UserPrefs openURLsWithPreferredBrowser:urls];
}
// if success == NO, do not modify unread state
if (!openLinks || success) {
for (FeedArticle *fa in list) {
fa.unread = !markRead;
}
[StoreCoordinator saveContext:moc andParent:YES];
[moc reset];
NSNumber *num = [NSNumber numberWithInteger: (markRead ? -1 : +1) * (NSInteger)list.count ];
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationTotalUnreadCountChanged object:num];
}
[StoreCoordinator saveContext:moc andParent:YES];
[moc reset];
if (openLinks)
[UserPrefs openURLsWithPreferredBrowser:urls];
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationTotalUnreadCountChanged object:countDiff];
}
@end