Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 committed Oct 17, 2024
1 parent 857d741 commit 84e1cdf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
via: via,
clientProxy: userSession.clientProxy,
mediaProvider: userSession.mediaProvider,
userIndicatorController: userIndicatorController))
userIndicatorController: userIndicatorController,
appSettings: appSettings))

joinRoomScreenCoordinator = coordinator

Expand Down
7 changes: 7 additions & 0 deletions ElementX/Sources/Other/Extensions/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,10 @@ extension String {
return result
}
}

extension String {
/// detects if the string is empty or contains only whitespaces and newlines
var isBlank: Bool {
trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct JoinRoomScreenCoordinatorParameters {
let clientProxy: ClientProxyProtocol
let mediaProvider: MediaProviderProtocol
let userIndicatorController: UserIndicatorControllerProtocol
let appSettings: AppSettings
}

enum JoinRoomScreenCoordinatorAction {
Expand All @@ -34,7 +35,7 @@ final class JoinRoomScreenCoordinator: CoordinatorProtocol {
init(parameters: JoinRoomScreenCoordinatorParameters) {
viewModel = JoinRoomScreenViewModel(roomID: parameters.roomID,
via: parameters.via,
appSettings: ServiceLocator.shared.settings,
appSettings: parameters.appSettings,
clientProxy: parameters.clientProxy,
mediaProvider: parameters.mediaProvider,
userIndicatorController: parameters.userIndicatorController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ struct JoinRoomScreenViewState: BindableState {
var avatar: RoomAvatar {
roomDetails?.avatar ?? .room(id: roomID, name: title, avatarURL: nil)
}

var isEmptyKnockMessage: Bool {
bindings.knockMessage.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
}
}

struct JoinRoomScreenViewStateBindings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,9 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
return
}

if roomPreviewDetails?.isPublic ?? false {
state.mode = .join
} else if roomPreviewDetails?.canKnock ?? false, appSettings.knockingEnabled {
if roomPreviewDetails?.canKnock ?? false, appSettings.knockingEnabled {
state.mode = .knock
} else {
// If everything else fails fallback to showing the join button and
// letting the server figure it out.
state.mode = .join
}
}
Expand Down Expand Up @@ -190,7 +186,7 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo

if let alias = state.roomDetails?.canonicalAlias {
switch await clientProxy.knockRoomAlias(alias,
message: state.isEmptyKnockMessage ? nil : state.bindings.knockMessage) {
message: state.bindings.knockMessage.isBlank ? nil : state.bindings.knockMessage) {
case .success:
state.mode = .knocked
case .failure(let error):
Expand All @@ -199,7 +195,7 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
}
} else {
switch await clientProxy.knockRoom(roomID,
message: state.isEmptyKnockMessage ? nil : state.bindings.knockMessage) {
message: state.bindings.knockMessage.isBlank ? nil : state.bindings.knockMessage) {
case .success:
state.mode = .knocked
case .failure(let error):
Expand Down

0 comments on commit 84e1cdf

Please sign in to comment.