diff --git a/baRSS/Notifications/NotifyEndpoint.h b/baRSS/Notifications/NotifyEndpoint.h index 382ed32..c64413e 100644 --- a/baRSS/Notifications/NotifyEndpoint.h +++ b/baRSS/Notifications/NotifyEndpoint.h @@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN @interface NotifyEndpoint : NSObject + (void)activate; -+ (void)setGlobalCount:(NSUInteger)count; ++ (void)setGlobalCount:(NSInteger)count previousCount:(NSInteger)count; + (void)postFeed:(Feed*)feed; + (void)postArticle:(FeedArticle*)article; diff --git a/baRSS/Notifications/NotifyEndpoint.m b/baRSS/Notifications/NotifyEndpoint.m index 9662805..1a14ed9 100644 --- a/baRSS/Notifications/NotifyEndpoint.m +++ b/baRSS/Notifications/NotifyEndpoint.m @@ -45,17 +45,19 @@ static NotificationType notifyType; } /// Set (or update) global "X unread articles" -+ (void)setGlobalCount:(NSUInteger)count { ++ (void)setGlobalCount:(NSInteger)newCount previousCount:(NSInteger)oldCount { if (notifyType != NotificationTypeGlobal) { return; } - if (count > 0) { + if (newCount > 0) { // TODO: how to handle global count updates? // ignore and keep old count until 0? // or update count and show a new notification banner? - [self send:kNotifyIdGlobal - title:nil - body:[NSString stringWithFormat:@"%ld unread articles", count]]; + if (newCount > oldCount) { // only notify if new feeds (quirk: will also trigger for option-click menu to mark unread) + [self send:kNotifyIdGlobal + title:nil + body:[NSString stringWithFormat:@"%ld unread articles", newCount]]; + } } else { [self dismiss:@[kNotifyIdGlobal]]; } diff --git a/baRSS/Status Bar Menu/BarStatusItem.m b/baRSS/Status Bar Menu/BarStatusItem.m index 1d3d21b..8f6f488 100644 --- a/baRSS/Status Bar Menu/BarStatusItem.m +++ b/baRSS/Status Bar Menu/BarStatusItem.m @@ -70,19 +70,21 @@ /// Assign total unread count value directly. - (void)setUnreadCountAbsolute:(NSUInteger)count { + NSInteger oldCount = _unreadCountTotal; _unreadCountTotal = count > 0 ? (NSInteger)count : 0; [self updateBarIcon]; - [NotifyEndpoint setGlobalCount:count]; + [NotifyEndpoint setGlobalCount:_unreadCountTotal previousCount:oldCount]; } /// Assign new value by adding @c count to total unread count (may be negative). - (void)setUnreadCountRelative:(NSInteger)count { + NSInteger oldCount = _unreadCountTotal; _unreadCountTotal += count; if (_unreadCountTotal < 0) { _unreadCountTotal = 0; } [self updateBarIcon]; - [NotifyEndpoint setGlobalCount:(NSUInteger)_unreadCountTotal]; + [NotifyEndpoint setGlobalCount:_unreadCountTotal previousCount:oldCount]; } /// Fetch new total unread count from core data and assign it as new value (dispatch async on main thread).