Fix: Mark blocks of reappearing ghost items as read

This commit is contained in:
relikd
2019-04-02 15:52:03 +02:00
parent 7004db25e5
commit a1b91e51f9
3 changed files with 15 additions and 21 deletions

View File

@@ -118,7 +118,6 @@
54E8831D211B509D00064188 /* ModalFeedEdit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModalFeedEdit.h; sourceTree = "<group>"; }; 54E8831D211B509D00064188 /* ModalFeedEdit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModalFeedEdit.h; sourceTree = "<group>"; };
54E8831E211B509D00064188 /* ModalFeedEdit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ModalFeedEdit.m; sourceTree = "<group>"; }; 54E8831E211B509D00064188 /* ModalFeedEdit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ModalFeedEdit.m; sourceTree = "<group>"; };
54E8831F211B509D00064188 /* ModalFeedEdit.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ModalFeedEdit.xib; sourceTree = "<group>"; }; 54E8831F211B509D00064188 /* ModalFeedEdit.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ModalFeedEdit.xib; sourceTree = "<group>"; };
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 = "<group>"; }; 54F6025B21C1D4170006D338 /* OpmlExport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OpmlExport.h; sourceTree = "<group>"; };
54F6025C21C1D4170006D338 /* OpmlExport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OpmlExport.m; sourceTree = "<group>"; }; 54F6025C21C1D4170006D338 /* OpmlExport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OpmlExport.m; sourceTree = "<group>"; };
54FE73CE21220DEC003EAC65 /* StoreCoordinator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StoreCoordinator.h; sourceTree = "<group>"; }; 54FE73CE21220DEC003EAC65 /* StoreCoordinator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StoreCoordinator.h; sourceTree = "<group>"; };
@@ -172,7 +171,6 @@
544FBD4321064AEB008A260C /* Frameworks */ = { 544FBD4321064AEB008A260C /* Frameworks */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
54F518772162CA4F00EE856C /* ServiceManagement.framework */,
544DCCB8212A2B4D002DBC46 /* RSXML.framework */, 544DCCB8212A2B4D002DBC46 /* RSXML.framework */,
544DCCBD212A2B6F002DBC46 /* RSXML.framework.dSYM */, 544DCCBD212A2B6F002DBC46 /* RSXML.framework.dSYM */,
); );

View File

@@ -113,38 +113,34 @@
@param remoteSet Readonly copy of @c RSParsedFeed.articles. @param remoteSet Readonly copy of @c RSParsedFeed.articles.
*/ */
- (NSUInteger)insertArticles:(NSMutableSet<FeedArticle*>*)localSet withRemoteSet:(NSArray<RSParsedArticle*>*)remoteSet { - (NSUInteger)insertArticles:(NSMutableSet<FeedArticle*>*)localSet withRemoteSet:(NSArray<RSParsedArticle*>*)remoteSet {
NSUInteger newOnes = 0;
int32_t currentIndex = [[localSet valueForKeyPath:@"@min.sortIndex"] intValue]; int32_t currentIndex = [[localSet valueForKeyPath:@"@min.sortIndex"] intValue];
FeedArticle *lastInserted = nil; NSMutableArray<FeedArticle*>* newlyInserted = [NSMutableArray arrayWithCapacity:remoteSet.count];
BOOL hasGapBetweenNewArticles = NO;
for (RSParsedArticle *article in [remoteSet reverseObjectEnumerator]) { for (RSParsedArticle *article in [remoteSet reverseObjectEnumerator]) {
// reverse enumeration ensures correct article order // reverse enumeration ensures correct article order
FeedArticle *storedArticle = [self findRemoteArticle:article inLocalSet:localSet]; FeedArticle *storedArticle = [self findRemoteArticle:article inLocalSet:localSet];
if (storedArticle) { if (storedArticle) {
[localSet removeObject: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) { if (storedArticle.sortIndex != currentIndex) {
storedArticle.sortIndex = currentIndex; storedArticle.sortIndex = currentIndex;
} }
hasGapBetweenNewArticles = YES;
} else { } else {
newOnes += 1; FeedArticle *newArticle = [FeedArticle newArticle:article inContext:self.managedObjectContext];
if (hasGapBetweenNewArticles && lastInserted) { // gap with at least one article inbetween newArticle.sortIndex = currentIndex;
lastInserted.unread = NO; [self addArticlesObject:newArticle];
newOnes -= 1; [newlyInserted addObject:newArticle];
}
hasGapBetweenNewArticles = NO;
lastInserted = [FeedArticle newArticle:article inContext:self.managedObjectContext];
lastInserted.sortIndex = currentIndex;
[self addArticlesObject:lastInserted];
} }
currentIndex += 1; currentIndex += 1;
} }
if (hasGapBetweenNewArticles && lastInserted) { return newlyInserted.count; // all ghost items are removed already
lastInserted.unread = NO;
newOnes -= 1;
}
return newOnes;
} }
/** /**

View File

@@ -32,7 +32,7 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1184</string> <string>1207</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string> <string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key> <key>LSUIElement</key>