mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Show or create direct message room (#716)
* add start chat flow with UI * add feature flag for start chat * add changelog * fix naming and tests * fix empty display name in user cell * Update ElementX/Sources/Application/AppSettings.swift Co-authored-by: Alfonso Grillo <alfogrillo@element.io> * add screenshots from UI test * fix swiftFormat and add identifiers * fix warnings * add the create or open already existing direct room feature * add changelog * add UserProfile object, add loading indicator in start chat flow * fix test * add new section for user profile in start chat * fix duplicates input on search bar * Update ElementX/Sources/Services/Client/ClientProxy.swift Co-authored-by: Alfonso Grillo <alfogrillo@element.io> * Update ElementX/Sources/Services/Client/ClientProxy.swift Co-authored-by: Alfonso Grillo <alfogrillo@element.io> --------- Co-authored-by: Alfonso Grillo <alfogrillo@element.io>
This commit is contained in:
@@ -143,6 +143,29 @@ class ClientProxy: ClientProxyProtocol {
|
||||
slidingSyncObserverToken = nil
|
||||
}
|
||||
|
||||
func directRoomForUserID(_ userID: String) async -> Result<String?, ClientProxyError> {
|
||||
await Task.dispatch(on: clientQueue) {
|
||||
do {
|
||||
let roomId = try self.client.getDmRoom(userId: userID)?.id()
|
||||
return .success(roomId)
|
||||
} catch {
|
||||
return .failure(.failedRetrievingDirectRoom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func createDirectRoom(with userID: String) async -> Result<String, ClientProxyError> {
|
||||
await Task.dispatch(on: clientQueue) {
|
||||
do {
|
||||
let parameters = CreateRoomParameters(name: "", topic: nil, isEncrypted: true, isDirect: true, visibility: .private, preset: .trustedPrivateChat, invite: [userID], avatar: nil)
|
||||
let result = try self.client.createRoom(request: parameters)
|
||||
return .success(result)
|
||||
} catch {
|
||||
return .failure(.failedCreatingRoom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol? {
|
||||
let (slidingSyncRoom, room) = await Task.dispatch(on: clientQueue) {
|
||||
self.roomTupleForIdentifier(identifier)
|
||||
|
||||
@@ -24,6 +24,8 @@ enum ClientProxyCallback {
|
||||
}
|
||||
|
||||
enum ClientProxyError: Error {
|
||||
case failedCreatingRoom
|
||||
case failedRetrievingDirectRoom
|
||||
case failedRetrievingDisplayName
|
||||
case failedRetrievingAccountData
|
||||
case failedSettingAccountData
|
||||
@@ -70,6 +72,10 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
|
||||
|
||||
func stopSync()
|
||||
|
||||
func directRoomForUserID(_ userID: String) async -> Result<String?, ClientProxyError>
|
||||
|
||||
func createDirectRoom(with userID: String) async -> Result<String, ClientProxyError>
|
||||
|
||||
func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol?
|
||||
|
||||
func loadUserDisplayName() async -> Result<String, ClientProxyError>
|
||||
|
||||
@@ -43,6 +43,14 @@ class MockClientProxy: ClientProxyProtocol {
|
||||
|
||||
func stopSync() { }
|
||||
|
||||
func directRoomForUserID(_ userID: String) async -> Result<String?, ClientProxyError> {
|
||||
.failure(.failedRetrievingDirectRoom)
|
||||
}
|
||||
|
||||
func createDirectRoom(with userID: String) async -> Result<String, ClientProxyError> {
|
||||
.failure(.failedCreatingRoom)
|
||||
}
|
||||
|
||||
func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol? {
|
||||
guard let room = visibleRoomsSummaryProvider?.roomListPublisher.value.first(where: { $0.id == identifier }) else {
|
||||
return nil
|
||||
|
||||
@@ -260,13 +260,16 @@ class UserSessionFlowCoordinator: CoordinatorProtocol {
|
||||
|
||||
let userIndicatorController = UserIndicatorController(rootCoordinator: startChatNavigationStackCoordinator)
|
||||
|
||||
let parameters = StartChatCoordinatorParameters(userSession: userSession)
|
||||
let parameters = StartChatCoordinatorParameters(userSession: userSession, userIndicatorController: userIndicatorController)
|
||||
let coordinator = StartChatCoordinator(parameters: parameters)
|
||||
coordinator.callback = { [weak self] action in
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .close:
|
||||
self.navigationSplitCoordinator.setSheetCoordinator(nil)
|
||||
case .openRoom(let identifier):
|
||||
self.navigationSplitCoordinator.setSheetCoordinator(nil)
|
||||
self.stateMachine.processEvent(.selectRoom(roomId: identifier))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// Copyright 2023 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
|
||||
import MatrixRustSDK
|
||||
|
||||
struct UserProfileProxy {
|
||||
let userID: String
|
||||
let displayName: String?
|
||||
let avatarURL: URL?
|
||||
|
||||
init(userID: String, displayName: String?, avatarURL: URL?) {
|
||||
self.userID = userID
|
||||
self.displayName = displayName
|
||||
self.avatarURL = avatarURL
|
||||
}
|
||||
|
||||
init(userProfile: UserProfile) {
|
||||
userID = userProfile.userId
|
||||
displayName = userProfile.displayName
|
||||
avatarURL = userProfile.avatarUrl.flatMap(URL.init(string:))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user