Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of the JoinRoomScreen. #2684

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion ElementX.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/element-hq/compound-ios",
"state" : {
"revision" : "ed63ed56655956c950a3b9c55e2010fdf1a2d11d"
"revision" : "43310aaaced1a0861c39894bb1086067375326be"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "join-room-graphic.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ElementX/Sources/Application/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
case .roomMemberDetails:
userSessionFlowCoordinator?.handleAppRoute(route, animated: true)
case .room(let roomID):
// check that the room is joined here, if not use a joinRoom route.
if isExternalURL {
userSessionFlowCoordinator?.handleAppRoute(route, animated: true)
} else {
Expand Down
1 change: 1 addition & 0 deletions ElementX/Sources/Generated/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal enum Asset {
internal static let stopRecording = ImageAsset(name: "images/stop-recording")
internal static let settingsIconWithBadge = ImageAsset(name: "images/settings-icon-with-badge")
internal static let joinRoomBackground = ImageAsset(name: "images/join-room-background")
internal static let joinRoomGraphic = ImageAsset(name: "images/join-room-graphic")
internal static let launchBackground = ImageAsset(name: "images/launch-background")
internal static let locationMarkerShape = ImageAsset(name: "images/location-marker-shape")
internal static let mediaPause = ImageAsset(name: "images/media-pause")
Expand Down
3 changes: 3 additions & 0 deletions ElementX/Sources/Other/AvatarSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ enum RoomAvatarSizeOnScreen {
case details
case notificationSettings
case roomDirectorySearch
case joinRoom

var value: CGFloat {
switch self {
Expand All @@ -110,6 +111,8 @@ enum RoomAvatarSizeOnScreen {
return 52
case .details:
return 70
case .joinRoom:
return 96
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct RoomDirectorySearchView: View {
Button(action: onTap) {
Label(L10n.screenRoomlistRoomDirectoryButtonTitle, icon: \.listBulleted)
}
.buttonStyle(.compound(.secondary))
.buttonStyle(.compound(.super))
.padding(.horizontal, 16)
.padding(.vertical, 8)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Combine
import SwiftUI

struct JoinRoomScreenCoordinatorParameters {
let roomID: String
let roomName: String
let avatarURL: URL?
let interaction: JoinRoomScreenInteraction
let clientProxy: ClientProxyProtocol
}

enum JoinRoomScreenCoordinatorAction {
case joined
case cancelled
}

final class JoinRoomScreenCoordinator: CoordinatorProtocol {
private let parameters: JoinRoomScreenCoordinatorParameters
private let viewModel: JoinRoomScreenViewModelProtocol

private var cancellables = Set<AnyCancellable>()

private let actionsSubject: PassthroughSubject<JoinRoomScreenCoordinatorAction, Never> = .init()
var actionsPublisher: AnyPublisher<JoinRoomScreenCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}

init(parameters: JoinRoomScreenCoordinatorParameters) {
self.parameters = parameters

viewModel = JoinRoomScreenViewModel(roomID: parameters.roomID,
roomName: parameters.roomName,
avatarURL: parameters.avatarURL,
interaction: parameters.interaction,
clientProxy: parameters.clientProxy)
}

func start() {
viewModel.actionsPublisher.sink { [weak self] action in
MXLog.info("Coordinator: received view model action: \(action)")

guard let self else { return }
switch action {
case .joined:
actionsSubject.send(.joined)
case .cancelled:
actionsSubject.send(.cancelled)
}
}
.store(in: &cancellables)
}

func toPresentable() -> AnyView {
AnyView(JoinRoomScreen(context: viewModel.context))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

enum JoinRoomScreenViewModelAction {
case joined
case cancelled
}

struct JoinRoomScreenViewState: BindableState {
// Maybe use room summary details or similar here??
let roomID: String
let roomName: String
let avatarURL: URL?

let interaction: JoinRoomScreenInteraction

var isJoining = false

var bindings = JoinRoomScreenViewStateBindings()

var title: String {
switch interaction {
case .knock:
L10n.screenJoinRoomTitleKnock
case .join, .invited:
L10n.screenJoinRoomTitleNoPreview
}
}

var subtitle: String {
switch interaction {
case .knock:
L10n.screenJoinRoomSubtitleKnock
case .join, .invited:
L10n.screenJoinRoomSubtitleNoPreview
}
}
}

struct JoinRoomScreenViewStateBindings {
var alertInfo: AlertInfo<JoinRoomScreenAlertType>?
}

enum JoinRoomScreenAlertType {
case joinFailed
}

enum JoinRoomScreenInteraction {
case knock
case join
case invited
}

enum JoinRoomScreenViewAction {
case knock
case join
case acceptInvite
case declineInvite
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Combine
import SwiftUI

typealias JoinRoomScreenViewModelType = StateStoreViewModel<JoinRoomScreenViewState, JoinRoomScreenViewAction>

class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewModelProtocol {
private let clientProxy: ClientProxyProtocol

private let actionsSubject: PassthroughSubject<JoinRoomScreenViewModelAction, Never> = .init()
var actionsPublisher: AnyPublisher<JoinRoomScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}

init(roomID: String, roomName: String, avatarURL: URL?, interaction: JoinRoomScreenInteraction, clientProxy: ClientProxyProtocol) {
self.clientProxy = clientProxy

super.init(initialViewState: JoinRoomScreenViewState(roomID: roomID,
roomName: roomName,
avatarURL: avatarURL,
interaction: interaction))
}

// MARK: - Public

override func process(viewAction: JoinRoomScreenViewAction) {
MXLog.info("View model: received view action: \(viewAction)")

switch viewAction {
case .knock:
break
case .join:
Task { await joinRoom() }
case .acceptInvite:
break
case .declineInvite:
break
}
}

// MARK: - Private

private func joinRoom() async {
state.isJoining = true
switch await clientProxy.joinRoom(state.roomID) {
case .success:
actionsSubject.send(.joined)
case .failure(let error):
state.bindings.alertInfo = .init(id: .joinFailed)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Combine

@MainActor
protocol JoinRoomScreenViewModelProtocol {
var actionsPublisher: AnyPublisher<JoinRoomScreenViewModelAction, Never> { get }
var context: JoinRoomScreenViewModelType.Context { get }
}
Loading
Loading