Skip to content

Commit

Permalink
suggested PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 committed Feb 5, 2025
1 parent ca50f37 commit 301b7a9
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 4 additions & 0 deletions ElementX/Sources/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct RoomMemberDetailsScreenViewStateBindings {

var ignoreUserAlert: IgnoreUserAlertItem?
var alertInfo: AlertInfo<RoomMemberDetailsScreenAlertType>?
var sheetItem: UserToInvite?
var sheetItem: UserProfileProxy?

/// A media item that will be previewed with QuickLook.
var mediaPreviewItem: MediaPreviewItem?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ struct StartChatScreenViewStateBindings {
/// Information describing the currently displayed alert.
var alertInfo: AlertInfo<StartChatScreenErrorType>?

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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}

Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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) {
Expand All @@ -43,17 +43,17 @@ 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) {
Text(L10n.screenBottomSheetCreateDmTitle)
.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)
Expand Down Expand Up @@ -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) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct UserProfileScreenViewState: BindableState {

struct UserProfileScreenViewStateBindings {
var alertInfo: AlertInfo<UserProfileScreenAlertType>?
var sheetItem: UserToInvite?
var sheetItem: UserProfileProxy?

/// A media item that will be previewed with QuickLook.
var mediaPreviewItem: MediaPreviewItem?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions ElementX/Sources/Services/Users/UserProfileProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ extension SearchUsersResultsProxy {
limited = sdkResults.limited
}
}

extension UserProfileProxy: Identifiable {
var id: String { userID }
}

0 comments on commit 301b7a9

Please sign in to comment.