Skip to content

Commit

Permalink
Add a setting to hide grey unread messages badges.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Feb 1, 2024
1 parent 497177e commit b1cd076
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
/* Used for testing */
"untranslated" = "Untranslated";

// MARK: - Notification Settings
"screen_notification_settings_hide_unread_badges" = "Sanity mode";
"screen_notification_settings_hide_unread_badges_description" = "Hide unread badges for rooms set to mute or mentions and keywords.";

// MARK: - Soft logout

"soft_logout_signin_title" = "Sign in";
Expand Down
6 changes: 6 additions & 0 deletions ElementX/Sources/Application/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ final class AppSettings {
case richTextEditorEnabled
case appAppearance
case sendReadReceiptsEnabled
case hideUnreadMessagesBadge

case elementCallBaseURL
case elementCallEncryptionEnabled
Expand Down Expand Up @@ -212,6 +213,11 @@ final class AppSettings {
@UserPreference(key: UserDefaultsKeys.analyticsConsentState, defaultValue: AnalyticsConsentState.unknown, storageType: .userDefaults(store))
var analyticsConsentState

// MARK: - Home Screen

@UserPreference(key: UserDefaultsKeys.hideUnreadMessagesBadge, defaultValue: false, storageType: .userDefaults(store))
var hideUnreadMessagesBadge

// MARK: - Room Screen

@UserPreference(key: UserDefaultsKeys.timelineStyle, defaultValue: TimelineStyle.bubbles, storageType: .userDefaults(store))
Expand Down
4 changes: 4 additions & 0 deletions ElementX/Sources/Generated/Strings+Untranslated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import Foundation
// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length
// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces
public enum UntranslatedL10n {
/// Sanity mode
public static var screenNotificationSettingsHideUnreadBadges: String { return UntranslatedL10n.tr("Untranslated", "screen_notification_settings_hide_unread_badges") }
/// Hide unread badges for rooms set to mute or mentions and keywords.
public static var screenNotificationSettingsHideUnreadBadgesDescription: String { return UntranslatedL10n.tr("Untranslated", "screen_notification_settings_hide_unread_badges_description") }
/// Clear all data currently stored on this device?
/// Sign in again to access your account data and messages.
public static var softLogoutClearDataDialogContent: String { return UntranslatedL10n.tr("Untranslated", "soft_logout_clear_data_dialog_content") }
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated using Sourcery 2.1.3 — https://github.com/krzysztofzablocki/Sourcery
// Generated using Sourcery 2.1.4 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT

// swiftlint:disable all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
.weakAssign(to: \.state.shouldShowFilters, on: self)
.store(in: &cancellables)

appSettings.$hideUnreadMessagesBadge
.sink { [weak self] _ in self?.updateRooms() }
.store(in: &cancellables)

let isSearchFieldFocused = context.$viewState.map(\.bindings.isSearchFieldFocused)
let searchQuery = context.$viewState.map(\.bindings.searchQuery)
isSearchFieldFocused
Expand Down Expand Up @@ -327,7 +331,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
return HomeScreenRoom(id: identifier,
roomId: details.id,
name: details.name,
hasUnreadMessages: details.unreadMessagesCount > 0,
hasUnreadMessages: appSettings.hideUnreadMessagesBadge ? false : details.unreadMessagesCount > 0,
hasUnreadMentions: details.unreadMentionsCount > 0,
hasUnreadNotifications: details.unreadNotificationsCount > 0,
hasOngoingCall: details.hasOngoingCall,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct NotificationSettingsScreenViewStateBindings {
var roomMentionsEnabled = false
var callsEnabled = false
var invitationsEnabled = false
var hideUnreadMessagesBadge = false
var alertInfo: AlertInfo<NotificationSettingsScreenErrorType>?
}

Expand Down Expand Up @@ -95,6 +96,7 @@ enum NotificationSettingsScreenViewAction {
case roomMentionChanged
case callsChanged
case invitationsChanged
case hideUnreadMessagesBadgeChanged
case close
case fixConfigurationMismatchTapped
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
self.userNotificationCenter = userNotificationCenter
self.notificationSettingsProxy = notificationSettingsProxy

let bindings = NotificationSettingsScreenViewStateBindings(enableNotifications: appSettings.enableNotifications)
let bindings = NotificationSettingsScreenViewStateBindings(enableNotifications: appSettings.enableNotifications,
hideUnreadMessagesBadge: appSettings.hideUnreadMessagesBadge)
super.init(initialViewState: NotificationSettingsScreenViewState(bindings: bindings, isModallyPresented: isModallyPresented))

// Listen for changes to AppSettings.enableNotifications
// Listen for changes to AppSettings.
appSettings.$enableNotifications
.weakAssign(to: \.state.bindings.enableNotifications, on: self)
.store(in: &cancellables)

appSettings.$hideUnreadMessagesBadge
.weakAssign(to: \.state.bindings.hideUnreadMessagesBadge, on: self)
.store(in: &cancellables)

setupDidBecomeActiveSubscription()
setupNotificationSettingsSubscription()
}
Expand Down Expand Up @@ -77,6 +82,8 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
return
}
Task { await enableInvitations(state.bindings.invitationsEnabled) }
case .hideUnreadMessagesBadgeChanged:
appSettings.hideUnreadMessagesBadge = state.bindings.hideUnreadMessagesBadge
case .close:
actionsSubject.send(.close)
case .fixConfigurationMismatchTapped:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ struct NotificationSettingsScreen: View {
if context.viewState.showSystemNotificationsAlert {
userPermissionSection
}

enableNotificationSection

if context.enableNotifications {
roomsNotificationSection

if context.viewState.settings?.roomMentionsEnabled != nil {
mentionsSection
}

if context.viewState.showCallsSettings, context.viewState.settings?.callsEnabled != nil {
callsSection
}
if context.viewState.settings?.invitationsEnabled != nil {
additionalSettingsSection
}

additionalSettingsSection
}
}
}
Expand Down Expand Up @@ -158,12 +161,21 @@ struct NotificationSettingsScreen: View {

private var additionalSettingsSection: some View {
Section {
ListRow(label: .plain(title: L10n.screenNotificationSettingsInviteForMeLabel),
kind: .toggle($context.invitationsEnabled))
.disabled(context.viewState.settings?.invitationsEnabled == nil)
.allowsHitTesting(!context.viewState.applyingChange)
.onChange(of: context.invitationsEnabled) { _ in
context.send(viewAction: .invitationsChanged)
if context.viewState.settings?.invitationsEnabled != nil {
ListRow(label: .plain(title: L10n.screenNotificationSettingsInviteForMeLabel),
kind: .toggle($context.invitationsEnabled))
.disabled(context.viewState.settings?.invitationsEnabled == nil)
.allowsHitTesting(!context.viewState.applyingChange)
.onChange(of: context.invitationsEnabled) { _ in
context.send(viewAction: .invitationsChanged)
}
}

ListRow(label: .plain(title: UntranslatedL10n.screenNotificationSettingsHideUnreadBadges,
description: UntranslatedL10n.screenNotificationSettingsHideUnreadBadgesDescription),
kind: .toggle($context.hideUnreadMessagesBadge))
.onChange(of: context.hideUnreadMessagesBadge) { _ in
context.send(viewAction: .hideUnreadMessagesBadgeChanged)
}
} header: {
Text(L10n.screenNotificationSettingsAdditionalSettingsSectionTitle)
Expand Down

0 comments on commit b1cd076

Please sign in to comment.