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

View File

@@ -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?
[self send:kNotifyIdGlobal if (newCount > oldCount) { // only notify if new feeds (quirk: will also trigger for option-click menu to mark unread)
title:nil [self send:kNotifyIdGlobal
body:[NSString stringWithFormat:@"%ld unread articles", count]]; title:nil
body:[NSString stringWithFormat:@"%ld unread articles", newCount]];
}
} else { } else {
[self dismiss:@[kNotifyIdGlobal]]; [self dismiss:@[kNotifyIdGlobal]];
} }

View File

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