From a1b91e51f93a492169d956c1caf7934180e2ed37 Mon Sep 17 00:00:00 2001 From: relikd Date: Tue, 2 Apr 2019 15:52:03 +0200 Subject: [PATCH] Fix: Mark blocks of reappearing ghost items as read --- baRSS.xcodeproj/project.pbxproj | 2 -- baRSS/Core Data/Feed+Ext.m | 32 ++++++++++++++------------------ baRSS/Info.plist | 2 +- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/baRSS.xcodeproj/project.pbxproj b/baRSS.xcodeproj/project.pbxproj index 68e12e9..57bdb29 100644 --- a/baRSS.xcodeproj/project.pbxproj +++ b/baRSS.xcodeproj/project.pbxproj @@ -118,7 +118,6 @@ 54E8831D211B509D00064188 /* ModalFeedEdit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModalFeedEdit.h; sourceTree = ""; }; 54E8831E211B509D00064188 /* ModalFeedEdit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ModalFeedEdit.m; sourceTree = ""; }; 54E8831F211B509D00064188 /* ModalFeedEdit.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ModalFeedEdit.xib; sourceTree = ""; }; - 54F518772162CA4F00EE856C /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = System/Library/Frameworks/ServiceManagement.framework; sourceTree = SDKROOT; }; 54F6025B21C1D4170006D338 /* OpmlExport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OpmlExport.h; sourceTree = ""; }; 54F6025C21C1D4170006D338 /* OpmlExport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OpmlExport.m; sourceTree = ""; }; 54FE73CE21220DEC003EAC65 /* StoreCoordinator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StoreCoordinator.h; sourceTree = ""; }; @@ -172,7 +171,6 @@ 544FBD4321064AEB008A260C /* Frameworks */ = { isa = PBXGroup; children = ( - 54F518772162CA4F00EE856C /* ServiceManagement.framework */, 544DCCB8212A2B4D002DBC46 /* RSXML.framework */, 544DCCBD212A2B6F002DBC46 /* RSXML.framework.dSYM */, ); diff --git a/baRSS/Core Data/Feed+Ext.m b/baRSS/Core Data/Feed+Ext.m index 75ca69d..f88cc42 100644 --- a/baRSS/Core Data/Feed+Ext.m +++ b/baRSS/Core Data/Feed+Ext.m @@ -113,38 +113,34 @@ @param remoteSet Readonly copy of @c RSParsedFeed.articles. */ - (NSUInteger)insertArticles:(NSMutableSet*)localSet withRemoteSet:(NSArray*)remoteSet { - NSUInteger newOnes = 0; int32_t currentIndex = [[localSet valueForKeyPath:@"@min.sortIndex"] intValue]; - FeedArticle *lastInserted = nil; - BOOL hasGapBetweenNewArticles = NO; + NSMutableArray* newlyInserted = [NSMutableArray arrayWithCapacity:remoteSet.count]; for (RSParsedArticle *article in [remoteSet reverseObjectEnumerator]) { // reverse enumeration ensures correct article order FeedArticle *storedArticle = [self findRemoteArticle:article inLocalSet:localSet]; if (storedArticle) { [localSet removeObject:storedArticle]; + // If we encounter an already existing item, assume newly inserted are "ghost" items and mark read. + if (newlyInserted.count > 0) { + for (FeedArticle *ghostItem in newlyInserted) { + ghostItem.unread = NO; + } + [newlyInserted removeAllObjects]; + } + // Ensures consecutive block of incrementing numbers on sortIndex if (storedArticle.sortIndex != currentIndex) { storedArticle.sortIndex = currentIndex; } - hasGapBetweenNewArticles = YES; } else { - newOnes += 1; - if (hasGapBetweenNewArticles && lastInserted) { // gap with at least one article inbetween - lastInserted.unread = NO; - newOnes -= 1; - } - hasGapBetweenNewArticles = NO; - lastInserted = [FeedArticle newArticle:article inContext:self.managedObjectContext]; - lastInserted.sortIndex = currentIndex; - [self addArticlesObject:lastInserted]; + FeedArticle *newArticle = [FeedArticle newArticle:article inContext:self.managedObjectContext]; + newArticle.sortIndex = currentIndex; + [self addArticlesObject:newArticle]; + [newlyInserted addObject:newArticle]; } currentIndex += 1; } - if (hasGapBetweenNewArticles && lastInserted) { - lastInserted.unread = NO; - newOnes -= 1; - } - return newOnes; + return newlyInserted.count; // all ghost items are removed already } /** diff --git a/baRSS/Info.plist b/baRSS/Info.plist index 73c55c2..2d33dc8 100644 --- a/baRSS/Info.plist +++ b/baRSS/Info.plist @@ -32,7 +32,7 @@ CFBundleVersion - 1184 + 1207 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) LSUIElement