From 301b7a9538ed19b1748e305c50fbde47444b2362 Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Wed, 5 Feb 2025 12:44:02 +0100 Subject: [PATCH] suggested PR changes --- .../en-US.lproj/Localizable.strings | 1 + .../en.lproj/Localizable.strings | 1 + ElementX/Sources/Generated/Strings.swift | 4 +++ .../RoomMemberDetailsScreenModels.swift | 2 +- .../RoomMemberDetailsScreenViewModel.swift | 2 +- .../StartChatScreenModels.swift | 4 +-- .../StartChatScreenViewModel.swift | 10 +++---- .../View/SendInviteConfirmationView.swift | 26 +++++++++---------- .../View/StartChatScreen.swift | 2 +- .../UserProfileScreenModels.swift | 2 +- .../UserProfileScreenViewModel.swift | 4 +-- .../Services/Users/UserProfileProxy.swift | 4 +++ 12 files changed, 35 insertions(+), 27 deletions(-) diff --git a/ElementX/Resources/Localizations/en-US.lproj/Localizable.strings b/ElementX/Resources/Localizations/en-US.lproj/Localizable.strings index d91b75e6b2..9c3b1c02e0 100644 --- a/ElementX/Resources/Localizations/en-US.lproj/Localizable.strings +++ b/ElementX/Resources/Localizations/en-US.lproj/Localizable.strings @@ -372,6 +372,7 @@ "screen_advanced_settings_element_call_base_url_validation_error" = "Invalid URL, please make sure you include the protocol (http/https) and the correct address."; "screen_bottom_sheet_create_dm_confirmation_button_title" = "Send invite"; "screen_bottom_sheet_create_dm_message" = "Would you like to start a chat with %1$@ (%2$@)?"; +"screen_bottom_sheet_create_dm_message_no_displayname" = "Would you like to start a chat with %1$@?"; "screen_bottom_sheet_create_dm_title" = "Send invite?"; "screen_create_room_room_access_section_anyone_option_description" = "Anyone can join this room"; "screen_create_room_room_access_section_anyone_option_title" = "Anyone"; diff --git a/ElementX/Resources/Localizations/en.lproj/Localizable.strings b/ElementX/Resources/Localizations/en.lproj/Localizable.strings index dac19a3eee..94b9c0d73f 100644 --- a/ElementX/Resources/Localizations/en.lproj/Localizable.strings +++ b/ElementX/Resources/Localizations/en.lproj/Localizable.strings @@ -372,6 +372,7 @@ "screen_advanced_settings_element_call_base_url_validation_error" = "Invalid URL, please make sure you include the protocol (http/https) and the correct address."; "screen_bottom_sheet_create_dm_confirmation_button_title" = "Send invite"; "screen_bottom_sheet_create_dm_message" = "Would you like to start a chat with %1$@ (%2$@)?"; +"screen_bottom_sheet_create_dm_message_no_displayname" = "Would you like to start a chat with %1$@?"; "screen_bottom_sheet_create_dm_title" = "Send invite?"; "screen_create_room_room_access_section_anyone_option_description" = "Anyone can join this room"; "screen_create_room_room_access_section_anyone_option_title" = "Anyone"; diff --git a/ElementX/Sources/Generated/Strings.swift b/ElementX/Sources/Generated/Strings.swift index f42c9734f4..8fe017f985 100644 --- a/ElementX/Sources/Generated/Strings.swift +++ b/ElementX/Sources/Generated/Strings.swift @@ -1020,6 +1020,10 @@ internal enum L10n { internal static func screenBottomSheetCreateDmMessage(_ p1: Any, _ p2: Any) -> String { return L10n.tr("Localizable", "screen_bottom_sheet_create_dm_message", String(describing: p1), String(describing: p2)) } + /// Would you like to start a chat with %1$@? + internal static func screenBottomSheetCreateDmMessageNoDisplayname(_ p1: Any) -> String { + return L10n.tr("Localizable", "screen_bottom_sheet_create_dm_message_no_displayname", String(describing: p1)) + } /// Send invite? internal static var screenBottomSheetCreateDmTitle: String { return L10n.tr("Localizable", "screen_bottom_sheet_create_dm_title") } /// Attach screenshot diff --git a/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenModels.swift b/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenModels.swift index 129c446b62..fc0ca78b0a 100644 --- a/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenModels.swift +++ b/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenModels.swift @@ -73,7 +73,7 @@ struct RoomMemberDetailsScreenViewStateBindings { var ignoreUserAlert: IgnoreUserAlertItem? var alertInfo: AlertInfo? - var sheetItem: UserToInvite? + var sheetItem: UserProfileProxy? /// A media item that will be previewed with QuickLook. var mediaPreviewItem: MediaPreviewItem? diff --git a/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenViewModel.swift b/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenViewModel.swift index c85cb65c0f..62d89c73e4 100644 --- a/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenViewModel.swift @@ -189,7 +189,7 @@ class RoomMemberDetailsScreenViewModel: RoomMemberDetailsScreenViewModelType, Ro if let roomID { actionsSubject.send(.openDirectChat(roomID: roomID)) } else { - state.bindings.sheetItem = .init(avatarUrl: roomMemberProxy.avatarURL, displayName: roomMemberProxy.displayName, id: roomMemberProxy.userID) + state.bindings.sheetItem = .init(userID: roomMemberProxy.userID, displayName: roomMemberProxy.displayName, avatarURL: roomMemberProxy.avatarURL) } case .failure: state.bindings.alertInfo = .init(id: .failedOpeningDirectChat) diff --git a/ElementX/Sources/Screens/StartChatScreen/StartChatScreenModels.swift b/ElementX/Sources/Screens/StartChatScreen/StartChatScreenModels.swift index ddf5eb3dab..8beb78ad0b 100644 --- a/ElementX/Sources/Screens/StartChatScreen/StartChatScreenModels.swift +++ b/ElementX/Sources/Screens/StartChatScreen/StartChatScreenModels.swift @@ -38,12 +38,12 @@ struct StartChatScreenViewStateBindings { /// Information describing the currently displayed alert. var alertInfo: AlertInfo? - var selectedUserToInvite: UserToInvite? + var selectedUserToInvite: UserProfileProxy? } enum StartChatScreenViewAction { case close case createRoom - case createDM(userID: String, displayName: String?) + case createDM(user: UserProfileProxy) case selectUser(UserProfileProxy) } diff --git a/ElementX/Sources/Screens/StartChatScreen/StartChatScreenViewModel.swift b/ElementX/Sources/Screens/StartChatScreen/StartChatScreenViewModel.swift index 0ec3e37b21..17c23b1e26 100644 --- a/ElementX/Sources/Screens/StartChatScreen/StartChatScreenViewModel.swift +++ b/ElementX/Sources/Screens/StartChatScreen/StartChatScreenViewModel.swift @@ -63,14 +63,14 @@ class StartChatScreenViewModel: StartChatScreenViewModelType, StartChatScreenVie actionsSubject.send(.openRoom(withIdentifier: roomId)) case .success: hideLoadingIndicator() - state.bindings.selectedUserToInvite = .init(avatarUrl: user.avatarURL, displayName: user.displayName, id: user.userID) + state.bindings.selectedUserToInvite = user case .failure: hideLoadingIndicator() displayError() } } - case .createDM(let userID, let displayName): - Task { await createDirectRoom(userID: userID, displayName: displayName) } + case .createDM(let user): + Task { await createDirectRoom(user: user) } } } @@ -110,12 +110,12 @@ class StartChatScreenViewModel: StartChatScreenViewModelType, StartChatScreenVie } } - private func createDirectRoom(userID: String, displayName: String?) async { + private func createDirectRoom(user: UserProfileProxy) async { defer { hideLoadingIndicator() } showLoadingIndicator() - switch await userSession.clientProxy.createDirectRoom(with: userID, expectedRoomName: displayName) { + switch await userSession.clientProxy.createDirectRoom(with: user.userID, expectedRoomName: user.displayName) { case .success(let roomId): analytics.trackCreatedRoom(isDM: true) actionsSubject.send(.openRoom(withIdentifier: roomId)) diff --git a/ElementX/Sources/Screens/StartChatScreen/View/SendInviteConfirmationView.swift b/ElementX/Sources/Screens/StartChatScreen/View/SendInviteConfirmationView.swift index 2f0eb47d67..283e398833 100644 --- a/ElementX/Sources/Screens/StartChatScreen/View/SendInviteConfirmationView.swift +++ b/ElementX/Sources/Screens/StartChatScreen/View/SendInviteConfirmationView.swift @@ -8,16 +8,8 @@ import Compound import SwiftUI -struct UserToInvite: Identifiable { - let avatarUrl: URL? - let displayName: String? - - /// User ID - let id: String -} - struct SendInviteConfirmationView: View { - let userToInvite: UserToInvite + let userToInvite: UserProfileProxy let mediaProvider: MediaProviderProtocol? let onInvite: () -> Void @@ -26,6 +18,14 @@ struct SendInviteConfirmationView: View { @State private var sheetHeight: CGFloat = .zero private let topPadding: CGFloat = 24 + var subtitle: String { + if let displayName = userToInvite.displayName { + L10n.screenBottomSheetCreateDmMessage(displayName, userToInvite.userID) + } else { + L10n.screenBottomSheetCreateDmMessageNoDisplayname(userToInvite.userID) + } + } + var body: some View { ScrollView { VStack(spacing: 40) { @@ -43,9 +43,9 @@ struct SendInviteConfirmationView: View { private var header: some View { VStack(spacing: 16) { - LoadableAvatarImage(url: userToInvite.avatarUrl, + LoadableAvatarImage(url: userToInvite.avatarURL, name: userToInvite.displayName, - contentID: userToInvite.id, + contentID: userToInvite.userID, avatarSize: .user(on: .sendInviteConfirmation), mediaProvider: mediaProvider) VStack(spacing: 8) { @@ -53,7 +53,7 @@ struct SendInviteConfirmationView: View { .multilineTextAlignment(.center) .font(.compound.headingMDBold) .foregroundStyle(.compound.textPrimary) - Text(L10n.screenBottomSheetCreateDmMessage(userToInvite.displayName ?? "", userToInvite.id)) + Text(subtitle) .multilineTextAlignment(.center) .font(.compound.bodyMD) .foregroundStyle(.compound.textSecondary) @@ -89,7 +89,7 @@ struct SendInviteConfirmationView: View { struct SendInviteConfirmationView_Previews: PreviewProvider, TestablePreview { static var previews: some View { - SendInviteConfirmationView(userToInvite: .init(avatarUrl: nil, displayName: "Alice", id: "@alice:matrix.org"), + SendInviteConfirmationView(userToInvite: .mockAlice, mediaProvider: nil) { } } } diff --git a/ElementX/Sources/Screens/StartChatScreen/View/StartChatScreen.swift b/ElementX/Sources/Screens/StartChatScreen/View/StartChatScreen.swift index c4c1464468..a3ce20b9d9 100644 --- a/ElementX/Sources/Screens/StartChatScreen/View/StartChatScreen.swift +++ b/ElementX/Sources/Screens/StartChatScreen/View/StartChatScreen.swift @@ -33,7 +33,7 @@ struct StartChatScreen: View { .alert(item: $context.alertInfo) .sheet(item: $context.selectedUserToInvite) { user in SendInviteConfirmationView(userToInvite: user, mediaProvider: context.mediaProvider) { - context.send(viewAction: .createDM(userID: user.id, displayName: user.displayName)) + context.send(viewAction: .createDM(user: user)) } } } diff --git a/ElementX/Sources/Screens/UserProfileScreen/UserProfileScreenModels.swift b/ElementX/Sources/Screens/UserProfileScreen/UserProfileScreenModels.swift index 7a2a7c7086..ce8ab1c69f 100644 --- a/ElementX/Sources/Screens/UserProfileScreen/UserProfileScreenModels.swift +++ b/ElementX/Sources/Screens/UserProfileScreen/UserProfileScreenModels.swift @@ -36,7 +36,7 @@ struct UserProfileScreenViewState: BindableState { struct UserProfileScreenViewStateBindings { var alertInfo: AlertInfo? - var sheetItem: UserToInvite? + var sheetItem: UserProfileProxy? /// A media item that will be previewed with QuickLook. var mediaPreviewItem: MediaPreviewItem? diff --git a/ElementX/Sources/Screens/UserProfileScreen/UserProfileScreenViewModel.swift b/ElementX/Sources/Screens/UserProfileScreen/UserProfileScreenViewModel.swift index 6a61a6812a..da3beeacec 100644 --- a/ElementX/Sources/Screens/UserProfileScreen/UserProfileScreenViewModel.swift +++ b/ElementX/Sources/Screens/UserProfileScreen/UserProfileScreenViewModel.swift @@ -123,9 +123,7 @@ class UserProfileScreenViewModel: UserProfileScreenViewModelType, UserProfileScr if let roomID { actionsSubject.send(.openDirectChat(roomID: roomID)) } else { - state.bindings.sheetItem = .init(avatarUrl: userProfile.avatarURL, - displayName: userProfile.displayName, - id: userProfile.userID) + state.bindings.sheetItem = userProfile } case .failure: state.bindings.alertInfo = .init(id: .failedOpeningDirectChat) diff --git a/ElementX/Sources/Services/Users/UserProfileProxy.swift b/ElementX/Sources/Services/Users/UserProfileProxy.swift index 0abb703b76..a0035d2fb1 100644 --- a/ElementX/Sources/Services/Users/UserProfileProxy.swift +++ b/ElementX/Sources/Services/Users/UserProfileProxy.swift @@ -55,3 +55,7 @@ extension SearchUsersResultsProxy { limited = sdkResults.limited } } + +extension UserProfileProxy: Identifiable { + var id: String { userID } +}