feat: no global notify if marking articles read

This commit is contained in:
relikd
2025-10-25 12:36:57 +02:00
parent 3235bffdca
commit 0b6a338fa3
3 changed files with 12 additions and 8 deletions

View File

@@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface NotifyEndpoint : NSObject <UNUserNotificationCenterDelegate>
+ (void)activate;
+ (void)setGlobalCount:(NSUInteger)count;
+ (void)setGlobalCount:(NSInteger)count previousCount:(NSInteger)count;
+ (void)postFeed:(Feed*)feed;
+ (void)postArticle:(FeedArticle*)article;

View File

@@ -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]];
}

View File

@@ -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).