From 6faa575e76f1dd6b7bd0a13fed30d83e230d4f8a Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Mon, 23 Sep 2024 13:43:17 +0200 Subject: [PATCH] message pinning ff removal --- .../Sources/Application/AppSettings.swift | 3 -- .../RoomDetailsScreenModels.swift | 1 - .../RoomDetailsScreenViewModel.swift | 9 ++---- .../View/RoomDetailsScreen.swift | 28 +++++++------------ .../Screens/RoomScreen/RoomScreenModels.swift | 3 +- .../RoomScreen/RoomScreenViewModel.swift | 11 ++------ .../DeveloperOptionsScreenModels.swift | 1 - .../View/DeveloperOptionsScreen.swift | 7 ----- .../Screens/Timeline/TimelineViewModel.swift | 7 ++--- .../Style/TimelineItemBubbledStylerView.swift | 4 +-- .../Sources/Services/Client/ClientProxy.swift | 9 ++---- .../Sources/TimelineViewModelTests.swift | 2 -- 12 files changed, 20 insertions(+), 65 deletions(-) diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index 44a07da5f3..8e774fc097 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -271,9 +271,6 @@ final class AppSettings { @UserPreference(key: UserDefaultsKeys.fuzzyRoomListSearchEnabled, defaultValue: false, storageType: .userDefaults(store)) var fuzzyRoomListSearchEnabled - @UserPreference(key: UserDefaultsKeys.pinningEnabled, defaultValue: true, storageType: .userDefaults(store)) - var pinningEnabled - enum SlidingSyncDiscovery: Codable { case proxy, native, forceNative } @UserPreference(key: UserDefaultsKeys.slidingSyncDiscovery, defaultValue: .native, storageType: .userDefaults(store)) var slidingSyncDiscovery: SlidingSyncDiscovery diff --git a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenModels.swift b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenModels.swift index 77a328956f..b7c5dfe09d 100644 --- a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenModels.swift +++ b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenModels.swift @@ -44,7 +44,6 @@ struct RoomDetailsScreenViewState: BindableState { var canEditRolesOrPermissions = false var notificationSettingsState: RoomDetailsNotificationSettingsState = .loading var canJoinCall = false - var isPinningEnabled = false var pinnedEventsActionState = RoomDetailsScreenPinnedEventsActionState.loading var canEdit: Bool { diff --git a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift index 79e83484e2..999b942ff4 100644 --- a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift @@ -75,13 +75,8 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr bindings: .init()), mediaProvider: mediaProvider) - appSettings.$pinningEnabled - .weakAssign(to: \.state.isPinningEnabled, on: self) - .store(in: &cancellables) - - appSettings.$pinningEnabled - .combineLatest(appMediator.networkMonitor.reachabilityPublisher) - .filter { $0.0 && $0.1 == .reachable } + appMediator.networkMonitor.reachabilityPublisher + .filter { $0 == .reachable } .receive(on: DispatchQueue.main) .sink { [weak self] _ in self?.setupPinnedEventsTimelineProviderIfNeeded() diff --git a/ElementX/Sources/Screens/RoomDetailsScreen/View/RoomDetailsScreen.swift b/ElementX/Sources/Screens/RoomDetailsScreen/View/RoomDetailsScreen.swift index 73a8446f98..61ae51a0c9 100644 --- a/ElementX/Sources/Screens/RoomDetailsScreen/View/RoomDetailsScreen.swift +++ b/ElementX/Sources/Screens/RoomDetailsScreen/View/RoomDetailsScreen.swift @@ -189,15 +189,13 @@ struct RoomDetailsScreen: View { context.send(viewAction: .toggleFavourite(isFavourite: newValue)) } - if context.viewState.isPinningEnabled { - ListRow(label: .default(title: L10n.screenRoomDetailsPinnedEventsRowTitle, - icon: \.pin), - details: context.viewState.pinnedEventsActionState.isLoading ? .isWaiting(true) : .title(context.viewState.pinnedEventsActionState.count), - kind: context.viewState.pinnedEventsActionState.isLoading ? .label : .navigationLink(action: { - context.send(viewAction: .processTapPinnedEvents) - })) - .disabled(context.viewState.pinnedEventsActionState.isLoading) - } + ListRow(label: .default(title: L10n.screenRoomDetailsPinnedEventsRowTitle, + icon: \.pin), + details: context.viewState.pinnedEventsActionState.isLoading ? .isWaiting(true) : .title(context.viewState.pinnedEventsActionState.count), + kind: context.viewState.pinnedEventsActionState.isLoading ? .label : .navigationLink(action: { + context.send(viewAction: .processTapPinnedEvents) + })) + .disabled(context.viewState.pinnedEventsActionState.isLoading) if context.viewState.canEditRolesOrPermissions, context.viewState.dmRecipient == nil { ListRow(label: .default(title: L10n.screenRoomDetailsRolesAndPermissions, @@ -320,8 +318,6 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview { var notificationSettingsProxyMockConfiguration = NotificationSettingsProxyMockConfiguration() notificationSettingsProxyMockConfiguration.roomMode.isDefault = false let notificationSettingsProxy = NotificationSettingsProxyMock(with: notificationSettingsProxyMockConfiguration) - let appSettings = AppSettings() - appSettings.pinningEnabled = true return RoomDetailsScreenViewModel(roomProxy: roomProxy, clientProxy: ClientProxyMock(.init()), @@ -331,7 +327,7 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview { notificationSettingsProxy: notificationSettingsProxy, attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), appMediator: AppMediatorMock.default, - appSettings: appSettings) + appSettings: ServiceLocator.shared.settings) }() static let dmRoomViewModel = { @@ -348,8 +344,6 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview { canonicalAlias: "#alias:domain.com", members: members)) let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init()) - let appSettings = AppSettings() - appSettings.pinningEnabled = true return RoomDetailsScreenViewModel(roomProxy: roomProxy, clientProxy: ClientProxyMock(.init()), @@ -359,7 +353,7 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview { notificationSettingsProxy: notificationSettingsProxy, attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), appMediator: AppMediatorMock.default, - appSettings: appSettings) + appSettings: ServiceLocator.shared.settings) }() static let simpleRoomViewModel = { @@ -375,8 +369,6 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview { isEncrypted: false, members: members)) let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init()) - let appSettings = AppSettings() - appSettings.pinningEnabled = true return RoomDetailsScreenViewModel(roomProxy: roomProxy, clientProxy: ClientProxyMock(.init()), @@ -386,7 +378,7 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview { notificationSettingsProxy: notificationSettingsProxy, attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), appMediator: AppMediatorMock.default, - appSettings: appSettings) + appSettings: ServiceLocator.shared.settings) }() static var previews: some View { diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift index cd2d31f02c..9f4bb68a22 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift @@ -28,11 +28,10 @@ struct RoomScreenViewState: BindableState { var roomAvatar: RoomAvatar var lastScrollDirection: ScrollDirection? - var isPinningEnabled = false // This is used to control the banner var pinnedEventsBannerState: PinnedEventsBannerState = .loading(numbersOfEvents: 0) var shouldShowPinnedEventsBanner: Bool { - isPinningEnabled && !pinnedEventsBannerState.isEmpty && lastScrollDirection != .top + !pinnedEventsBannerState.isEmpty && lastScrollDirection != .top } var canJoinCall = false diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index 8c33e3e3ad..990d304081 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -124,15 +124,8 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol } .store(in: &cancellables) - let pinningEnabledPublisher = appSettings.$pinningEnabled - - pinningEnabledPublisher - .weakAssign(to: \.state.isPinningEnabled, on: self) - .store(in: &cancellables) - - pinningEnabledPublisher - .combineLatest(appMediator.networkMonitor.reachabilityPublisher) - .filter { $0.0 && $0.1 == .reachable } + appMediator.networkMonitor.reachabilityPublisher + .filter { $0 == .reachable } .receive(on: DispatchQueue.main) .sink { [weak self] _ in self?.setupPinnedEventsTimelineProviderIfNeeded() diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift index 8ad26e512f..74bcdf4fbe 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift @@ -46,7 +46,6 @@ protocol DeveloperOptionsProtocol: AnyObject { var hideUnreadMessagesBadge: Bool { get set } var elementCallBaseURLOverride: URL? { get set } var fuzzyRoomListSearchEnabled: Bool { get set } - var pinningEnabled: Bool { get set } var invisibleCryptoEnabled: Bool { get set } } diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift index 7f9217f665..da28d85fb9 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift @@ -35,13 +35,6 @@ struct DeveloperOptionsScreen: View { Text(context.viewState.slidingSyncFooter) } - Section("Message Pinning") { - Toggle(isOn: $context.pinningEnabled) { - Text("Enable message pinning") - Text("Requires app reboot") - } - } - Section("Room List") { Toggle(isOn: $context.hideUnreadMessagesBadge) { Text("Hide grey dots") diff --git a/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift b/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift index c0557862bd..6dd87b4674 100644 --- a/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift +++ b/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift @@ -336,8 +336,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol { state.canCurrentUserRedactSelf = false } - if appSettings.pinningEnabled, - case let .success(value) = await roomProxy.canUserPinOrUnpin(userID: roomProxy.ownUserID) { + if case let .success(value) = await roomProxy.canUserPinOrUnpin(userID: roomProxy.ownUserID) { state.canCurrentUserPin = value } else { state.canCurrentUserPin = false @@ -443,9 +442,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol { } private func updatePinnedEventIDs() async { - if appSettings.pinningEnabled { - state.pinnedEventIDs = await roomProxy.pinnedEventIDs - } + state.pinnedEventIDs = await roomProxy.pinnedEventIDs } private func setupDirectRoomSubscriptionsIfNeeded() { diff --git a/ElementX/Sources/Screens/Timeline/View/Style/TimelineItemBubbledStylerView.swift b/ElementX/Sources/Screens/Timeline/View/Style/TimelineItemBubbledStylerView.swift index 32b33c57a8..adba1e5c37 100644 --- a/ElementX/Sources/Screens/Timeline/View/Style/TimelineItemBubbledStylerView.swift +++ b/ElementX/Sources/Screens/Timeline/View/Style/TimelineItemBubbledStylerView.swift @@ -355,8 +355,6 @@ private extension View { struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview { static let viewModel = TimelineViewModel.mock static let viewModelWithPins: TimelineViewModel = { - var settings = AppSettings() - settings.pinningEnabled = true let roomProxy = JoinedRoomProxyMock(.init(name: "Preview Room", pinnedEventIDs: [""])) return TimelineViewModel(roomProxy: roomProxy, focussedEventID: nil, @@ -366,7 +364,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview voiceMessageMediaManager: VoiceMessageMediaManagerMock(), userIndicatorController: ServiceLocator.shared.userIndicatorController, appMediator: AppMediatorMock.default, - appSettings: settings, + appSettings: ServiceLocator.shared.settings, analyticsService: ServiceLocator.shared.analytics) }() diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index b06c3e0cee..9a05854447 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -816,12 +816,13 @@ class ClientProxy: ClientProxyProtocol { }) } - private lazy var eventFilters: TimelineEventTypeFilter = { + private let eventFilters: TimelineEventTypeFilter = { var stateEventFilters: [StateEventType] = [.roomAliases, .roomCanonicalAlias, .roomGuestAccess, .roomHistoryVisibility, .roomJoinRules, + .roomPinnedEvents, .roomPowerLevels, .roomServerAcl, .roomTombstone, @@ -830,12 +831,6 @@ class ClientProxy: ClientProxyProtocol { .policyRuleRoom, .policyRuleServer, .policyRuleUser] - - // Reminder: once the feature flag is not required anymore, change the lazy var back to a let - if !appSettings.pinningEnabled { - stateEventFilters.append(.roomPinnedEvents) - } - return .exclude(eventTypes: stateEventFilters.map { FilterTimelineEventType.state(eventType: $0) }) }() diff --git a/UnitTests/Sources/TimelineViewModelTests.swift b/UnitTests/Sources/TimelineViewModelTests.swift index c4434c8f26..02451739bc 100644 --- a/UnitTests/Sources/TimelineViewModelTests.swift +++ b/UnitTests/Sources/TimelineViewModelTests.swift @@ -379,7 +379,6 @@ class TimelineViewModelTests: XCTestCase { // MARK: - Pins func testPinnedEvents() async throws { - ServiceLocator.shared.settings.pinningEnabled = true let roomProxyMock = JoinedRoomProxyMock(.init(name: "", pinnedEventIDs: .init(["test1"]))) let actionsSubject = PassthroughSubject() @@ -408,7 +407,6 @@ class TimelineViewModelTests: XCTestCase { } func testCanUserPinEvents() async throws { - ServiceLocator.shared.settings.pinningEnabled = true let roomProxyMock = JoinedRoomProxyMock(.init(name: "", canUserPin: false)) let actionsSubject = PassthroughSubject() roomProxyMock.underlyingActionsPublisher = actionsSubject.eraseToAnyPublisher()