feat: no global notify if marking articles read
This commit is contained in:
@@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@interface NotifyEndpoint : NSObject <UNUserNotificationCenterDelegate>
|
@interface NotifyEndpoint : NSObject <UNUserNotificationCenterDelegate>
|
||||||
+ (void)activate;
|
+ (void)activate;
|
||||||
|
|
||||||
+ (void)setGlobalCount:(NSUInteger)count;
|
+ (void)setGlobalCount:(NSInteger)count previousCount:(NSInteger)count;
|
||||||
+ (void)postFeed:(Feed*)feed;
|
+ (void)postFeed:(Feed*)feed;
|
||||||
+ (void)postArticle:(FeedArticle*)article;
|
+ (void)postArticle:(FeedArticle*)article;
|
||||||
|
|
||||||
|
|||||||
@@ -45,17 +45,19 @@ static NotificationType notifyType;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set (or update) global "X unread articles"
|
/// Set (or update) global "X unread articles"
|
||||||
+ (void)setGlobalCount:(NSUInteger)count {
|
+ (void)setGlobalCount:(NSInteger)newCount previousCount:(NSInteger)oldCount {
|
||||||
if (notifyType != NotificationTypeGlobal) {
|
if (notifyType != NotificationTypeGlobal) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (count > 0) {
|
if (newCount > 0) {
|
||||||
// TODO: how to handle global count updates?
|
// TODO: how to handle global count updates?
|
||||||
// ignore and keep old count until 0?
|
// ignore and keep old count until 0?
|
||||||
// or update count and show a new notification banner?
|
// or update count and show a new notification banner?
|
||||||
|
if (newCount > oldCount) { // only notify if new feeds (quirk: will also trigger for option-click menu to mark unread)
|
||||||
[self send:kNotifyIdGlobal
|
[self send:kNotifyIdGlobal
|
||||||
title:nil
|
title:nil
|
||||||
body:[NSString stringWithFormat:@"%ld unread articles", count]];
|
body:[NSString stringWithFormat:@"%ld unread articles", newCount]];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
[self dismiss:@[kNotifyIdGlobal]];
|
[self dismiss:@[kNotifyIdGlobal]];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,19 +70,21 @@
|
|||||||
|
|
||||||
/// Assign total unread count value directly.
|
/// Assign total unread count value directly.
|
||||||
- (void)setUnreadCountAbsolute:(NSUInteger)count {
|
- (void)setUnreadCountAbsolute:(NSUInteger)count {
|
||||||
|
NSInteger oldCount = _unreadCountTotal;
|
||||||
_unreadCountTotal = count > 0 ? (NSInteger)count : 0;
|
_unreadCountTotal = count > 0 ? (NSInteger)count : 0;
|
||||||
[self updateBarIcon];
|
[self updateBarIcon];
|
||||||
[NotifyEndpoint setGlobalCount:count];
|
[NotifyEndpoint setGlobalCount:_unreadCountTotal previousCount:oldCount];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Assign new value by adding @c count to total unread count (may be negative).
|
/// Assign new value by adding @c count to total unread count (may be negative).
|
||||||
- (void)setUnreadCountRelative:(NSInteger)count {
|
- (void)setUnreadCountRelative:(NSInteger)count {
|
||||||
|
NSInteger oldCount = _unreadCountTotal;
|
||||||
_unreadCountTotal += count;
|
_unreadCountTotal += count;
|
||||||
if (_unreadCountTotal < 0) {
|
if (_unreadCountTotal < 0) {
|
||||||
_unreadCountTotal = 0;
|
_unreadCountTotal = 0;
|
||||||
}
|
}
|
||||||
[self updateBarIcon];
|
[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).
|
/// Fetch new total unread count from core data and assign it as new value (dispatch async on main thread).
|
||||||
|
|||||||
Reference in New Issue
Block a user