Skip to content

Commit

Permalink
Fixes #3146 - Remove the account migration screen
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Sep 9, 2024
1 parent cce42a7 commit 65cda66
Show file tree
Hide file tree
Showing 13 changed files with 6 additions and 146 deletions.
14 changes: 0 additions & 14 deletions ElementX/Sources/Application/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,20 +356,6 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg

MXLog.info("The app was upgraded from \(oldVersion) to \(newVersion)")

if oldVersion < Version(1, 1, 0) {
MXLog.info("Migrating to v1.1.0, signing out the user.")
// Version 1.1.0 switched the Rust crypto store to SQLite
// There are no migrations in place so we need to sign the user out
wipeUserData()
}

if oldVersion < Version(1, 1, 7) {
MXLog.info("Migrating to v1.1.7, marking accounts as migrated.")
for userID in userSessionStore.userIDs {
appSettings.migratedAccounts[userID] = true
}
}

if oldVersion < Version(1, 6, 0) {
MXLog.info("Migrating to v1.6.0, marking identity confirmation onboarding as ran.")
if !userSessionStore.userIDs.isEmpty {
Expand Down
10 changes: 1 addition & 9 deletions ElementX/Sources/Application/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ final class AppSettings {
case lastVersionLaunched
case appLockNumberOfPINAttempts
case appLockNumberOfBiometricAttempts
case migratedAccounts
case timelineStyle

case analyticsConsentState
Expand Down Expand Up @@ -159,14 +158,7 @@ final class AppSettings {
contacts: [supportEmailAddress],
staticRegistrations: oidcStaticRegistrations.mapKeys { $0.absoluteString },
dynamicRegistrationsFile: .sessionsBaseDirectory.appending(path: "oidc/registrations.json"))

/// A dictionary of accounts that have performed an initial sync through their proxy.
///
/// This is a temporary workaround. In the future we should be able to receive a signal from the
/// proxy that it is the first sync (or that an upgrade on the backend will involve a slower sync).
@UserPreference(key: UserDefaultsKeys.migratedAccounts, defaultValue: [:], storageType: .userDefaults(store))
var migratedAccounts: [String: Bool]


// MARK: - Notifications

var pusherAppId: String {
Expand Down
5 changes: 0 additions & 5 deletions ElementX/Sources/Other/AccessibilityIdentifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ enum A11yIdentifiers {
static let roomMemberDetailsScreen = RoomMemberDetailsScreen()
static let createRoomScreen = CreateRoomScreen()
static let inviteUsersScreen = InviteUsersScreen()
static let migrationScreen = MigrationScreen()
static let notificationSettingsScreen = NotificationSettingsScreen()
static let notificationSettingsEditScreen = NotificationSettingsEditScreen()
static let pollFormScreen = PollFormScreen()
Expand Down Expand Up @@ -239,10 +238,6 @@ enum A11yIdentifiers {
"\(optionPrefix)-\(index)"
}
}

struct MigrationScreen {
let message = "migration_screen-message"
}

struct NotificationSettingsScreen {
let fixMismatchConfiguration = "notification_settings_screen-fix_mismatch_configuration"
Expand Down
3 changes: 0 additions & 3 deletions ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,12 @@ enum HomeScreenViewAction {
}

enum HomeScreenRoomListMode: CustomStringConvertible {
case migration
case skeletons
case empty
case rooms

var description: String {
switch self {
case .migration:
return "Showing account migration"
case .skeletons:
return "Showing placeholders"
case .empty:
Expand Down
29 changes: 1 addition & 28 deletions ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol

private let roomSummaryProvider: RoomSummaryProviderProtocol?

private var migrationCancellable: AnyCancellable?

private var actionsSubject: PassthroughSubject<HomeScreenViewModelAction, Never> = .init()
var actions: AnyPublisher<HomeScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
Expand Down Expand Up @@ -223,27 +221,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
}

analyticsService.signpost.beginFirstRooms()

let hasUserBeenMigrated = appSettings.migratedAccounts[userSession.clientProxy.userID] == true

if !hasUserBeenMigrated {
state.roomListMode = .migration

MXLog.info("Account not migrated, setting view room list mode to \"\(state.roomListMode)\"")

migrationCancellable = userSession.clientProxy.actionsPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] callback in
guard let self, case .receivedSyncUpdate = callback else { return }
migrationCancellable = nil
appSettings.migratedAccounts[userSession.clientProxy.userID] = true

MXLog.info("Received first sync response, updating room list mode")

updateRoomListMode(with: roomSummaryProvider.statePublisher.value)
}
}


roomSummaryProvider.statePublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] state in
Expand All @@ -262,11 +240,6 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
}

private func updateRoomListMode(with roomSummaryProviderState: RoomSummaryProviderState) {
guard appSettings.migratedAccounts[userSession.clientProxy.userID] == true else {
// Ignore room summary provider updates while "migrating"
return
}

let isLoadingData = !roomSummaryProviderState.isLoaded
let hasNoRooms = roomSummaryProviderState.isLoaded && roomSummaryProviderState.totalNumberOfRooms == 0

Expand Down
15 changes: 2 additions & 13 deletions ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,11 @@ struct HomeScreen: View {
// MARK: - Previews

struct HomeScreen_Previews: PreviewProvider, TestablePreview {
static let migratingViewModel = viewModel(.migration)
static let loadingViewModel = viewModel(.skeletons)
static let emptyViewModel = viewModel(.empty)
static let loadedViewModel = viewModel(.rooms)

static var previews: some View {
NavigationStack {
HomeScreen(context: migratingViewModel.context)
}
.previewDisplayName("Migrating")

NavigationStack {
HomeScreen(context: loadingViewModel.context)
}
Expand All @@ -218,14 +212,9 @@ struct HomeScreen_Previews: PreviewProvider, TestablePreview {
}

static func viewModel(_ mode: HomeScreenRoomListMode) -> HomeScreenViewModel {
let userID = mode == .migration ? "@unmigrated_alice:example.com" : "@alice:example.com"

let appSettings = AppSettings() // This uses shared storage under the hood
appSettings.migratedAccounts[userID] = mode != .migration
let userID = "@alice:example.com"

let roomSummaryProviderState: RoomSummaryProviderMockConfigurationState = switch mode {
case .migration:
.loading
case .skeletons:
.loading
case .empty:
Expand All @@ -241,7 +230,7 @@ struct HomeScreen_Previews: PreviewProvider, TestablePreview {

return HomeScreenViewModel(userSession: userSession,
analyticsService: ServiceLocator.shared.analytics,
appSettings: appSettings,
appSettings: ServiceLocator.shared.settings,
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
userIndicatorController: ServiceLocator.shared.userIndicatorController)
}
Expand Down
52 changes: 2 additions & 50 deletions ElementX/Sources/Screens/HomeScreen/View/HomeScreenContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ struct HomeScreenContent: View {
let scrollViewAdapter: ScrollViewAdapter

var body: some View {
switch context.viewState.roomListMode {
case .migration:
migrationView
default:
roomList
.sentryTrace("\(Self.self)")
}
roomList
.sentryTrace("\(Self.self)")
}

private var roomList: some View {
Expand Down Expand Up @@ -59,8 +54,6 @@ struct HomeScreenContent: View {
.searchable(text: $context.searchQuery, placement: .navigationBarDrawer(displayMode: .always))
.compoundSearchField()
.disableAutocorrection(true)
case .migration:
EmptyView()
}
}
.introspect(.scrollView, on: .supportedVersions) { scrollView in
Expand Down Expand Up @@ -141,47 +134,6 @@ struct HomeScreenContent: View {
}
}

@ViewBuilder
private var migrationView: some View {
if UIDevice.current.isPhone {
if verticalSizeClass == .compact {
migrationViewContent
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
WaitingDialog {
migrationViewContent
} bottomContent: {
EmptyView()
}
}
} else {
migrationViewContent
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}

private var migrationViewContent: some View {
VStack(spacing: 16) {
ProgressView()
.tint(.compound.iconPrimary)
.padding(.bottom, 4)

Text(L10n.screenMigrationTitle.tinting(".", color: Asset.Colors.brandColor.swiftUIColor))
.minimumScaleFactor(0.01)
.font(.compound.headingXLBold)
.multilineTextAlignment(.center)
.foregroundColor(.compound.textPrimary)

Text(L10n.screenMigrationMessage)
.minimumScaleFactor(0.01)
.font(.compound.bodyLG)
.multilineTextAlignment(.center)
.foregroundColor(.compound.textPrimary)
.accessibilityIdentifier(A11yIdentifiers.migrationScreen.message)
}
.padding(.horizontal)
}

/// Often times the scroll view's content size isn't correct yet when this method is called e.g. when cancelling a search
/// Dispatch it with a delay to allow the UI to update and the computations to be correct
/// Once we move to iOS 17 we should remove all of this and use scroll anchors instead
Expand Down
3 changes: 0 additions & 3 deletions ElementX/Sources/UITests/UITestsAppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ class MockScreen: Identifiable {
let navigationSplitCoordinator = NavigationSplitCoordinator(placeholderCoordinator: PlaceholderScreenCoordinator())

let clientProxy = ClientProxyMock(.init(userID: "@mock:client.com", deviceID: "MOCKCLIENT", roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms)))))
ServiceLocator.shared.settings.migratedAccounts[clientProxy.userID] = true

let appMediator = AppMediatorMock.default
appMediator.underlyingWindowManager = windowManager
Expand Down Expand Up @@ -635,8 +634,6 @@ class MockScreen: Identifiable {

clientProxy.roomForIdentifierReturnValue = .joined(roomProxy)

ServiceLocator.shared.settings.migratedAccounts[clientProxy.userID] = true

let timelineController = RoomTimelineController(roomProxy: roomProxy,
timelineProxy: roomProxy.timeline,
initialFocussedEventID: nil,
Expand Down
9 changes: 0 additions & 9 deletions IntegrationTests/Sources/Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ extension XCUIApplication {

savePasswordButton.tap()
}

// Migration screen may be shown as an overlay.
// if that pops up soon enough, we just let that happen and wait
let message = staticTexts[A11yIdentifiers.migrationScreen.message]

if message.waitForExistence(timeout: 10.0) {
currentTestCase.expectation(for: doesNotExistPredicate, evaluatedWith: message)
currentTestCase.waitForExpectations(timeout: 300.0)
}

// Wait for the home screen to become visible.
let profileButton = buttons[A11yIdentifiers.homeScreen.userAvatar]
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 65cda66

Please sign in to comment.