Rename isNotifyAboutNewArticles to shouldSendUserNotificationForNewArticles

This commit is contained in:
Brent Simmons 2024-05-25 23:05:38 -07:00
parent 33215ba9e3
commit 401050465e
6 changed files with 19 additions and 19 deletions

View File

@ -121,12 +121,12 @@ import Core
} }
} }
public var isNotifyAboutNewArticles: Bool? { public var shouldSendUserNotificationForNewArticles: Bool? {
get { get {
return metadata.isNotifyAboutNewArticles return metadata.shouldSendUserNotificationForNewArticles
} }
set { set {
metadata.isNotifyAboutNewArticles = newValue metadata.shouldSendUserNotificationForNewArticles = newValue
} }
} }

View File

@ -24,7 +24,7 @@ final class FeedMetadata: Codable {
case editedName case editedName
case authors case authors
case contentHash case contentHash
case isNotifyAboutNewArticles case shouldSendUserNotificationForNewArticles = "isNotifyAboutNewArticles"
case isArticleExtractorAlwaysOn case isArticleExtractorAlwaysOn
case conditionalGetInfo case conditionalGetInfo
case sinceToken case sinceToken
@ -74,10 +74,10 @@ final class FeedMetadata: Codable {
} }
} }
var isNotifyAboutNewArticles: Bool? { var shouldSendUserNotificationForNewArticles: Bool? {
didSet { didSet {
if isNotifyAboutNewArticles != oldValue { if shouldSendUserNotificationForNewArticles != oldValue {
valueDidChange(.isNotifyAboutNewArticles) valueDidChange(.shouldSendUserNotificationForNewArticles)
} }
} }
} }

View File

@ -80,14 +80,14 @@ import UserNotifications
} }
} else if settings.authorizationStatus == .authorized { } else if settings.authorizationStatus == .authorized {
DispatchQueue.main.async { DispatchQueue.main.async {
self.feed?.isNotifyAboutNewArticles = (self.isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false self.feed?.shouldSendUserNotificationForNewArticles = (self.isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false
} }
} else { } else {
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in
self.updateNotificationSettings() self.updateNotificationSettings()
if granted { if granted {
DispatchQueue.main.async { DispatchQueue.main.async {
self.feed?.isNotifyAboutNewArticles = (self.isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false self.feed?.shouldSendUserNotificationForNewArticles = (self.isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false
NSApplication.shared.registerForRemoteNotifications() NSApplication.shared.registerForRemoteNotifications()
} }
} else { } else {
@ -171,7 +171,7 @@ private extension FeedInspectorViewController {
func updateNotifyAboutNewArticles() { func updateNotifyAboutNewArticles() {
isNotifyAboutNewArticlesCheckBox?.title = feed?.notificationDisplayName ?? NSLocalizedString("Show notifications for new articles", comment: "Show notifications for new articles") isNotifyAboutNewArticlesCheckBox?.title = feed?.notificationDisplayName ?? NSLocalizedString("Show notifications for new articles", comment: "Show notifications for new articles")
isNotifyAboutNewArticlesCheckBox?.state = (feed?.isNotifyAboutNewArticles ?? false) ? .on : .off isNotifyAboutNewArticlesCheckBox?.state = (feed?.shouldSendUserNotificationForNewArticles ?? false) ? .on : .off
} }
func updateIsReaderViewAlwaysOn() { func updateIsReaderViewAlwaysOn() {

View File

@ -117,16 +117,16 @@ extension SidebarViewController {
self.showNotificationsNotEnabledAlert() self.showNotificationsNotEnabledAlert()
} else if settings.authorizationStatus == .authorized { } else if settings.authorizationStatus == .authorized {
DispatchQueue.main.async { DispatchQueue.main.async {
if feed.isNotifyAboutNewArticles == nil { feed.isNotifyAboutNewArticles = false } if feed.shouldSendUserNotificationForNewArticles == nil { feed.shouldSendUserNotificationForNewArticles = false }
feed.isNotifyAboutNewArticles?.toggle() feed.shouldSendUserNotificationForNewArticles?.toggle()
NotificationCenter.default.post(Notification(name: .DidUpdateFeedPreferencesFromContextMenu)) NotificationCenter.default.post(Notification(name: .DidUpdateFeedPreferencesFromContextMenu))
} }
} else { } else {
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in
if granted { if granted {
DispatchQueue.main.async { DispatchQueue.main.async {
if feed.isNotifyAboutNewArticles == nil { feed.isNotifyAboutNewArticles = false } if feed.shouldSendUserNotificationForNewArticles == nil { feed.shouldSendUserNotificationForNewArticles = false }
feed.isNotifyAboutNewArticles?.toggle() feed.shouldSendUserNotificationForNewArticles?.toggle()
NotificationCenter.default.post(Notification(name: .DidUpdateFeedPreferencesFromContextMenu)) NotificationCenter.default.post(Notification(name: .DidUpdateFeedPreferencesFromContextMenu))
NSApplication.shared.registerForRemoteNotifications() NSApplication.shared.registerForRemoteNotifications()
} }
@ -226,7 +226,7 @@ private extension SidebarViewController {
let notificationText = feed.notificationDisplayName.capitalized let notificationText = feed.notificationDisplayName.capitalized
let notificationMenuItem = menuItem(notificationText, #selector(toggleNotificationsFromContextMenu(_:)), feed) let notificationMenuItem = menuItem(notificationText, #selector(toggleNotificationsFromContextMenu(_:)), feed)
if feed.isNotifyAboutNewArticles == nil || feed.isNotifyAboutNewArticles! == false { if feed.shouldSendUserNotificationForNewArticles == nil || feed.shouldSendUserNotificationForNewArticles! == false {
notificationMenuItem.state = .off notificationMenuItem.state = .off
} else { } else {
notificationMenuItem.state = .on notificationMenuItem.state = .on

View File

@ -26,7 +26,7 @@ final class UserNotificationManager: Sendable {
Task { @MainActor in Task { @MainActor in
for article in articles { for article in articles {
if !article.status.read, let feed = article.feed, feed.isNotifyAboutNewArticles ?? false { if !article.status.read, let feed = article.feed, feed.shouldSendUserNotificationForNewArticles ?? false {
sendNotification(feed: feed, article: article) sendNotification(feed: feed, article: article)
} }
} }

View File

@ -42,7 +42,7 @@ class FeedInspectorViewController: UITableViewController {
navigationItem.title = feed.nameForDisplay navigationItem.title = feed.nameForDisplay
nameTextField.text = feed.nameForDisplay nameTextField.text = feed.nameForDisplay
notifyAboutNewArticlesSwitch.setOn(feed.isNotifyAboutNewArticles ?? false, animated: false) notifyAboutNewArticlesSwitch.setOn(feed.shouldSendUserNotificationForNewArticles ?? false, animated: false)
alwaysShowReaderViewSwitch.setOn(feed.isArticleExtractorAlwaysOn ?? false, animated: false) alwaysShowReaderViewSwitch.setOn(feed.isArticleExtractorAlwaysOn ?? false, animated: false)
@ -84,13 +84,13 @@ class FeedInspectorViewController: UITableViewController {
notifyAboutNewArticlesSwitch.isOn = !notifyAboutNewArticlesSwitch.isOn notifyAboutNewArticlesSwitch.isOn = !notifyAboutNewArticlesSwitch.isOn
present(notificationUpdateErrorAlert(), animated: true, completion: nil) present(notificationUpdateErrorAlert(), animated: true, completion: nil)
} else if settings.authorizationStatus == .authorized { } else if settings.authorizationStatus == .authorized {
feed.isNotifyAboutNewArticles = notifyAboutNewArticlesSwitch.isOn feed.shouldSendUserNotificationForNewArticles = notifyAboutNewArticlesSwitch.isOn
} else { } else {
UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .sound, .alert]) { (granted, error) in UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .sound, .alert]) { (granted, error) in
self.updateNotificationSettings() self.updateNotificationSettings()
if granted { if granted {
DispatchQueue.main.async { DispatchQueue.main.async {
self.feed.isNotifyAboutNewArticles = self.notifyAboutNewArticlesSwitch.isOn self.feed.shouldSendUserNotificationForNewArticles = self.notifyAboutNewArticlesSwitch.isOn
UIApplication.shared.registerForRemoteNotifications() UIApplication.shared.registerForRemoteNotifications()
} }
} else { } else {