Skip to content

Commit 542d382

Browse files
pixlwavestefanceriu
authored andcommitted
Add a developer option that hides notification alerts when a sound wouldn't be played.
Enabling this makes isNoisy behave like iMessage's Hide Alerts option.
1 parent 4adfa7c commit 542d382

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

ElementX/Sources/Application/AppSettings.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ protocol CommonSettingsProtocol {
1919
var enableOnlySignedDeviceIsolationMode: Bool { get }
2020
var hideInviteAvatars: Bool { get }
2121
var timelineMediaVisibility: TimelineMediaVisibility { get }
22+
var hideQuietNotificationAlerts: Bool { get }
2223
}
2324

2425
/// Store Element specific app settings.
@@ -45,7 +46,6 @@ final class AppSettings {
4546
case optimizeMediaUploads
4647
case appAppearance
4748
case sharePresence
48-
case hideUnreadMessagesBadge
4949
case hideInviteAvatars
5050
case timelineMediaVisibility
5151
case isNewBloomEnabled
@@ -59,6 +59,10 @@ final class AppSettings {
5959
case knockingEnabled
6060
case threadsEnabled
6161
case developerOptionsEnabled
62+
63+
// Doug's tweaks 🔧
64+
case hideUnreadMessagesBadge
65+
case hideQuietNotificationAlerts
6266
}
6367

6468
private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier
@@ -346,6 +350,9 @@ final class AppSettings {
346350
@UserPreference(key: UserDefaultsKeys.threadsEnabled, defaultValue: isDevelopmentBuild, storageType: .userDefaults(store))
347351
var developerOptionsEnabled
348352

353+
@UserPreference(key: UserDefaultsKeys.isNewBloomEnabled, defaultValue: false, storageType: .userDefaults(store))
354+
var isNewBloomEnabled
355+
349356
#endif
350357

351358
// MARK: - Shared
@@ -366,8 +373,8 @@ final class AppSettings {
366373
@UserPreference(key: UserDefaultsKeys.timelineMediaVisibility, defaultValue: TimelineMediaVisibility.always, storageType: .userDefaults(store))
367374
var timelineMediaVisibility
368375

369-
@UserPreference(key: UserDefaultsKeys.isNewBloomEnabled, defaultValue: false, storageType: .userDefaults(store))
370-
var isNewBloomEnabled
376+
@UserPreference(key: UserDefaultsKeys.hideQuietNotificationAlerts, defaultValue: false, storageType: .userDefaults(store))
377+
var hideQuietNotificationAlerts
371378
}
372379

373380
extension AppSettings: CommonSettingsProtocol { }

ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protocol DeveloperOptionsProtocol: AnyObject {
4646
var knockingEnabled: Bool { get set }
4747
var threadsEnabled: Bool { get set }
4848
var isNewBloomEnabled: Bool { get set }
49+
var hideQuietNotificationAlerts: Bool { get set }
4950
}
5051

5152
extension AppSettings: DeveloperOptionsProtocol { }

ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ struct DeveloperOptionsScreen: View {
9292
Text("Element Call remote URL override")
9393
}
9494

95+
Section("Notifications") {
96+
Toggle(isOn: $context.hideQuietNotificationAlerts) {
97+
Text("Hide quiet alerts")
98+
Text("The badge count will still be updated")
99+
}
100+
}
101+
95102
Section {
96103
Button {
97104
showConfetti = true

NSE/Sources/NotificationHandler.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class NotificationHandler {
8787
}
8888

8989
private func preprocessNotification(_ itemProxy: NotificationItemProxyProtocol) async -> NotificationProcessingResult {
90+
if settings.hideQuietNotificationAlerts, !itemProxy.isNoisy {
91+
return .processedShouldDiscard
92+
}
93+
9094
guard case let .timeline(event) = itemProxy.event else {
9195
return .shouldDisplay
9296
}

0 commit comments

Comments
 (0)