Skip to content

Commit

Permalink
Merge pull request #667 from barijaona/bugfixes
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
josh64x2 committed Jun 6, 2016
2 parents 89efe99 + 311325a commit 8fd28b3
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/AppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
NSMutableDictionary * scriptPathMappings;
NSMenu * appDockMenu;
NSStatusItem * appStatusItem;
NSInteger progressCount;
BOOL isProgressAnimatorActive;
NSDictionary * standardURLs;
NSTimer * checkTimer;
NSInteger lastCountOfUnread;
Expand Down
14 changes: 8 additions & 6 deletions src/AppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ -(instancetype)init
if ((self = [super init]) != nil)
{
scriptPathMappings = [[NSMutableDictionary alloc] init];
progressCount = 0;
isProgressAnimatorActive = NO;
persistedStatusText = nil;
lastCountOfUnread = 0;
appStatusItem = nil;
Expand Down Expand Up @@ -3900,20 +3900,22 @@ -(void)sendBlogEvent:(NSString *)externalEditorBundleIdentifier title:(NSString
*/
-(void)startProgressIndicator
{
if (progressCount++ == 0)
if (!isProgressAnimatorActive) {
[spinner startAnimation:self];
isProgressAnimatorActive = YES;
}
}

/* stopProgressIndicator
* Stops the progress indicator on the info bar running
*/
-(void)stopProgressIndicator
{
NSAssert(progressCount > 0, @"Called stopProgressIndicator without a matching startProgressIndicator");
if (--progressCount < 1)
NSAssert(isProgressAnimatorActive, @"Called stopProgressIndicator without a matching startProgressIndicator");
if (isProgressAnimatorActive)
{
[spinner stopAnimation:self];
progressCount = 0;
isProgressAnimatorActive = NO;
}
}

Expand Down Expand Up @@ -4547,7 +4549,7 @@ -(NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *

//Ensure the spinner has the proper state; it may be added while we're refreshing
if (APP.refreshing)
[spinner startAnimation:self];
[self startProgressIndicator];
}
else
{
Expand Down
42 changes: 13 additions & 29 deletions src/ArticleController.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ -(instancetype)init
// Register for notifications
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleFilterChange:) name:@"MA_Notify_FilteringChange" object:nil];
[nc addObserver:self selector:@selector(handleFolderUpdate:) name:@"MA_Notify_FoldersUpdated" object:nil];
[nc addObserver:self selector:@selector(handleRefreshArticle:) name:@"MA_Notify_ArticleViewChange" object:nil];
[nc addObserver:self selector:@selector(handleArticleListContentChange:) name:@"MA_Notify_ArticleListContentChange" object:nil];
[nc addObserver:self selector:@selector(handleArticleListStateChange:) name:@"MA_Notify_ArticleListStateChange" object:nil];

}
Expand Down Expand Up @@ -385,7 +385,8 @@ -(void)displayNextUnread
if (![mainArticleView viewNextUnreadInFolder])
{
// If nothing found, search if we have fresher articles from same folder
if ([[Database sharedManager] countOfUnread] > 1 && (![mainArticleView selectFirstUnreadInFolder] || self.selectedArticle == currentArticle))
if ( [[Database sharedManager] countOfUnread] > 0
&& (currentArticle == nil || ![mainArticleView selectFirstUnreadInFolder] || self.selectedArticle == currentArticle) )
{
// If nothing unread found in current folder, try other folders
NSInteger nextFolderWithUnread = [foldersTree nextFolderWithUnread:currentFolderId];
Expand Down Expand Up @@ -989,42 +990,25 @@ -(void)handleRefreshArticle:(NSNotification *)nc
}
}

/* handleFolderUpdate
* Called if a folder content has changed.
/* handleArticleListStateChange
* Called if a folder content has changed
* but we don't need to add new articles
*/
-(void)handleFolderUpdate:(NSNotification *)nc
-(void)handleArticleListStateChange:(NSNotification *)nc
{
@synchronized(mainArticleView)
{
NSInteger folderId = ((NSNumber *)nc.object).integerValue;
if (folderId != currentFolderId)
{
Folder * currentFolder = [[Database sharedManager] folderFromID:currentFolderId];
if ( !IsRSSFolder(currentFolder) && !IsGoogleReaderFolder(currentFolder) )
{
[mainArticleView refreshFolder:MA_Refresh_RedrawList];
}
return;
}

Folder * folder = [[Database sharedManager] folderFromID:folderId];
if (IsSmartFolder(folder) || IsTrashFolder(folder))
{
[mainArticleView refreshFolder:MA_Refresh_ReloadFromDatabase];
}
else
{
[mainArticleView refreshFolder:MA_Refresh_RedrawList];
}
NSInteger folderId = ((NSNumber *)nc.object).integerValue;
Folder * currentFolder = [[Database sharedManager] folderFromID:currentFolderId];
if ( (folderId == currentFolderId) || (!IsRSSFolder(currentFolder) && !IsGoogleReaderFolder(currentFolder)) ) {
[mainArticleView refreshFolder:MA_Refresh_RedrawList];
}
}

/* handleArticleListStateChange
/* handleArticleListContentChange
* called after a refresh
* or any other event which may have added a removed an article
* to the current folder
*/
-(void)handleArticleListStateChange:(NSNotification *)note
-(void)handleArticleListContentChange:(NSNotification *)note
{
NSInteger folderId = ((NSNumber *)note.object).integerValue;
Folder * currentFolder = [[Database sharedManager] folderFromID:currentFolderId];
Expand Down
77 changes: 38 additions & 39 deletions src/Folder.m
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,6 @@ -(NSArray *)arrayOfUnreadArticlesRefs
*/
-(NSArray *)articlesWithFilter:(NSString *)fstring
{
@synchronized(self)
{
if ([fstring isEqualToString:@""])
{
if (IsGroupFolder(self))
Expand All @@ -762,50 +760,51 @@ -(NSArray *)articlesWithFilter:(NSString *)fstring
}
return [articles copy];
}
if (isCached && containsBodies)
{
NSMutableArray * articles = [NSMutableArray arrayWithCapacity:self.cachedGuids.count];
for (id object in self.cachedGuids)
{
Article * theArticle = [self.cachedArticles objectForKey:object];
if (theArticle != nil)
[articles addObject:theArticle];
else
{ // some problem
NSLog(@"Bug retrieving from cache in folder %li : after %lu insertions of %lu, guid %@",(long)itemId, (unsigned long)articles.count,(unsigned long)self.cachedGuids.count,object);
isCached = NO;
containsBodies = NO;
break;
}
}
return [articles copy];
}
else
{
NSArray * articles = [[Database sharedManager] arrayOfArticles:itemId filterString:fstring];
// Only feeds folders can be cached, as they are the only ones to guarantee
// bijection : one article <-> one guid
if (IsRSSFolder(self) || IsGoogleReaderFolder(self))
@synchronized(self) {
if (isCached && containsBodies)
{
isCached = NO;
containsBodies = NO;
[self.cachedArticles removeAllObjects];
[self.cachedGuids removeAllObjects];
for (id object in articles)
NSMutableArray * articles = [NSMutableArray arrayWithCapacity:self.cachedGuids.count];
for (id object in self.cachedGuids)
{
NSString * guid = ((Article *)object).guid;
[self.cachedArticles setObject:object forKey:[NSString stringWithString:guid]];
[self.cachedGuids addObject:guid];
Article * theArticle = [self.cachedArticles objectForKey:object];
if (theArticle != nil)
[articles addObject:theArticle];
else
{ // some problem
NSLog(@"Bug retrieving from cache in folder %li : after %lu insertions of %lu, guid %@",(long)itemId, (unsigned long)articles.count,(unsigned long)self.cachedGuids.count,object);
isCached = NO;
containsBodies = NO;
break;
}
}
isCached = YES;
containsBodies = YES;
return [articles copy];
}
return articles;
}
else
{
NSArray * articles = [[Database sharedManager] arrayOfArticles:itemId filterString:fstring];
// Only feeds folders can be cached, as they are the only ones to guarantee
// bijection : one article <-> one guid
if (IsRSSFolder(self) || IsGoogleReaderFolder(self))
{
isCached = NO;
containsBodies = NO;
[self.cachedArticles removeAllObjects];
[self.cachedGuids removeAllObjects];
for (id object in articles)
{
NSString * guid = ((Article *)object).guid;
[self.cachedArticles setObject:object forKey:[NSString stringWithString:guid]];
[self.cachedGuids addObject:guid];
}
isCached = YES;
containsBodies = YES;
}
return articles;
}
} // synchronized
}
else
return [[Database sharedManager] arrayOfArticles:itemId filterString:fstring];
} //synchronized
}

/* folderNameCompare
Expand Down
4 changes: 4 additions & 0 deletions src/FoldersTree.m
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ -(NSInteger)nextFolderWithUnreadAfterNode:(TreeNode *)startingNode
{
node = startingNode.parentNode.nextSibling;
};
if (node ==nil)
{
node = startingNode.parentNode.firstChild;
}

if ( ((node.folder.childUnreadCount > 0) && ![outlineView isItemExpanded:node]) || (node.folder.unreadCount > 0) )
{
Expand Down
6 changes: 4 additions & 2 deletions src/GoogleReader.m
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ - (void)readRequestDone:(ASIHTTPRequest *)request
[[refreshedFolder articleFromGuid:guid] markRead:NO];
}
LLog(@"%ld unread items for %@", [guidArray count], [request url]);
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"MA_Notify_ArticleListStateChange" object:@(refreshedFolder.itemId)];
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"MA_Notify_ArticleListContentChange" object:@(refreshedFolder.itemId)];

[[Database sharedManager] markUnreadArticlesFromFolder:refreshedFolder guidArray:guidArray];
// reset starred statuses in cache : we will receive in -StarredRequestDone: the updated list
Expand Down Expand Up @@ -917,7 +917,9 @@ - (void)markReadDone:(ASIHTTPRequest *)request
BOOL readFlag = [[request.userInfo valueForKey:@"readFlag"] boolValue];
[[Database sharedManager] markArticleRead:article.folderId guid:article.guid isRead:readFlag];
[article markRead:readFlag];
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"MA_Notify_FoldersUpdated" object:@(article.folderId)];
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc postNotificationOnMainThreadWithName:@"MA_Notify_FoldersUpdated" object:@(article.folderId)];
[nc postNotificationOnMainThreadWithName:@"MA_Notify_ArticleListStateChange" object:@(article.folderId)];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/RefreshManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ -(void)finalizeFolderRefresh:(NSDictionary*)parameters;
{
NSString * logText = [NSString stringWithFormat:NSLocalizedString(@"%d new articles retrieved", nil), newArticlesFromFeed];
connectorItem.status = logText;
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"MA_Notify_ArticleListStateChange" object:@(folder.itemId)];
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"MA_Notify_ArticleListContentChange" object:@(folder.itemId)];
}

// Done with this connection
Expand Down

0 comments on commit 8fd28b3

Please sign in to comment.