mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
using roomPreview API for invited rooms (#3530)
* using roomPreview for invited rooms * Update ElementX/Sources/Services/Room/RoomInfoProxy.swift Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com> * improved code * fix, but requires a SDK PR * update sdk * package resolved * fixed the tests --------- Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
This commit is contained in:
@@ -5831,11 +5831,12 @@ class ElementCallWidgetDriverMock: ElementCallWidgetDriverProtocol {
|
||||
}
|
||||
}
|
||||
class InvitedRoomProxyMock: InvitedRoomProxyProtocol {
|
||||
var info: RoomInfoProxy {
|
||||
var info: BaseRoomInfoProxyProtocol {
|
||||
get { return underlyingInfo }
|
||||
set(value) { underlyingInfo = value }
|
||||
}
|
||||
var underlyingInfo: RoomInfoProxy!
|
||||
var underlyingInfo: BaseRoomInfoProxyProtocol!
|
||||
var inviter: RoomMemberProxyProtocol?
|
||||
var id: String {
|
||||
get { return underlyingId }
|
||||
set(value) { underlyingId = value }
|
||||
@@ -5911,70 +5912,6 @@ class InvitedRoomProxyMock: InvitedRoomProxyProtocol {
|
||||
return rejectInvitationReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - acceptInvitation
|
||||
|
||||
var acceptInvitationUnderlyingCallsCount = 0
|
||||
var acceptInvitationCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return acceptInvitationUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = acceptInvitationUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
acceptInvitationUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
acceptInvitationUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var acceptInvitationCalled: Bool {
|
||||
return acceptInvitationCallsCount > 0
|
||||
}
|
||||
|
||||
var acceptInvitationUnderlyingReturnValue: Result<Void, RoomProxyError>!
|
||||
var acceptInvitationReturnValue: Result<Void, RoomProxyError>! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return acceptInvitationUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Result<Void, RoomProxyError>? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = acceptInvitationUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
acceptInvitationUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
acceptInvitationUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var acceptInvitationClosure: (() async -> Result<Void, RoomProxyError>)?
|
||||
|
||||
func acceptInvitation() async -> Result<Void, RoomProxyError> {
|
||||
acceptInvitationCallsCount += 1
|
||||
if let acceptInvitationClosure = acceptInvitationClosure {
|
||||
return await acceptInvitationClosure()
|
||||
} else {
|
||||
return acceptInvitationReturnValue
|
||||
}
|
||||
}
|
||||
}
|
||||
class JoinedRoomProxyMock: JoinedRoomProxyProtocol {
|
||||
var isEncrypted: Bool {
|
||||
|
||||
@@ -23,6 +23,7 @@ extension InvitedRoomProxyMock {
|
||||
convenience init(_ configuration: InvitedRoomProxyMockConfiguration) {
|
||||
self.init()
|
||||
id = configuration.id
|
||||
inviter = configuration.inviter
|
||||
info = RoomInfoProxy(roomInfo: .init(configuration))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,7 +408,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
return
|
||||
}
|
||||
|
||||
switch await roomProxy.acceptInvitation() {
|
||||
switch await userSession.clientProxy.joinRoom(roomID, via: []) {
|
||||
case .success:
|
||||
actionsSubject.send(.presentRoom(roomIdentifier: roomID))
|
||||
analyticsService.trackJoinedRoom(isDM: roomProxy.info.isDirect,
|
||||
|
||||
@@ -109,7 +109,7 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
|
||||
case .joined(let joinedRoomProxy):
|
||||
roomPreviewInfo = joinedRoomProxy.infoPublisher.value
|
||||
case .invited(let invitedRoomProxy):
|
||||
inviter = invitedRoomProxy.info.inviter.flatMap(RoomInviterDetails.init)
|
||||
inviter = invitedRoomProxy.inviter.map(RoomInviterDetails.init)
|
||||
roomPreviewInfo = invitedRoomProxy.info
|
||||
case .knocked(let knockedRoomProxy):
|
||||
roomPreviewInfo = knockedRoomProxy.info
|
||||
|
||||
@@ -930,16 +930,15 @@ class ClientProxy: ClientProxyProtocol {
|
||||
switch roomListItem.membership() {
|
||||
case .invited:
|
||||
return try await .invited(InvitedRoomProxy(roomListItem: roomListItem,
|
||||
room: roomListItem.invitedRoom()))
|
||||
roomPreview: roomListItem.previewRoom(via: []),
|
||||
ownUserID: userID))
|
||||
case .knocked:
|
||||
if appSettings.knockingEnabled {
|
||||
return try await .knocked(KnockedRoomProxy(roomListItem: roomListItem,
|
||||
roomPreview: roomListItem.previewRoom(via: []),
|
||||
ownUserID: userID))
|
||||
} else {
|
||||
return try await .invited(InvitedRoomProxy(roomListItem: roomListItem,
|
||||
room: roomListItem.invitedRoom()))
|
||||
}
|
||||
return nil
|
||||
case .joined:
|
||||
if roomListItem.isTimelineInitialized() == false {
|
||||
try await roomListItem.initTimeline(eventTypeFilter: eventFilters, internalIdPrefix: nil)
|
||||
|
||||
@@ -11,36 +11,28 @@ import UIKit
|
||||
|
||||
class InvitedRoomProxy: InvitedRoomProxyProtocol {
|
||||
private let roomListItem: RoomListItemProtocol
|
||||
private let room: RoomProtocol
|
||||
private let roomPreview: RoomPreviewProtocol
|
||||
let info: BaseRoomInfoProxyProtocol
|
||||
let ownUserID: String
|
||||
let inviter: RoomMemberProxyProtocol?
|
||||
|
||||
// A room identifier is constant and lazy stops it from being fetched
|
||||
// multiple times over FFI
|
||||
lazy var id: String = room.id()
|
||||
|
||||
var ownUserID: String { room.ownUserId() }
|
||||
|
||||
let info: RoomInfoProxy
|
||||
|
||||
lazy var id: String = info.id
|
||||
|
||||
init(roomListItem: RoomListItemProtocol,
|
||||
room: RoomProtocol) async throws {
|
||||
roomPreview: RoomPreviewProtocol,
|
||||
ownUserID: String) async throws {
|
||||
self.roomListItem = roomListItem
|
||||
self.room = room
|
||||
info = try await RoomInfoProxy(roomInfo: room.roomInfo())
|
||||
}
|
||||
|
||||
func acceptInvitation() async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
try await room.join()
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed accepting invitation with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
self.roomPreview = roomPreview
|
||||
self.ownUserID = ownUserID
|
||||
info = try RoomPreviewInfoProxy(roomPreviewInfo: roomPreview.info())
|
||||
inviter = await roomPreview.inviter().map(RoomMemberProxy.init)
|
||||
}
|
||||
|
||||
func rejectInvitation() async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.leave())
|
||||
return try await .success(roomPreview.leave())
|
||||
} catch {
|
||||
MXLog.error("Failed rejecting invitiation with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
|
||||
@@ -13,16 +13,15 @@ class KnockedRoomProxy: KnockedRoomProxyProtocol {
|
||||
private let roomListItem: RoomListItemProtocol
|
||||
private let roomPreview: RoomPreviewProtocol
|
||||
let info: BaseRoomInfoProxyProtocol
|
||||
let ownUserID: String
|
||||
|
||||
// A room identifier is constant and lazy stops it from being fetched
|
||||
// multiple times over FFI
|
||||
lazy var id = info.id
|
||||
|
||||
let ownUserID: String
|
||||
|
||||
|
||||
init(roomListItem: RoomListItemProtocol,
|
||||
roomPreview: RoomPreviewProtocol,
|
||||
ownUserID: String) async throws {
|
||||
ownUserID: String) throws {
|
||||
self.roomListItem = roomListItem
|
||||
self.roomPreview = roomPreview
|
||||
self.ownUserID = ownUserID
|
||||
|
||||
@@ -16,6 +16,8 @@ protocol BaseRoomInfoProxyProtocol {
|
||||
var canonicalAlias: String? { get }
|
||||
var avatarURL: URL? { get }
|
||||
var activeMembersCount: Int { get }
|
||||
var isDirect: Bool { get }
|
||||
var isSpace: Bool { get }
|
||||
}
|
||||
|
||||
struct RoomInfoProxy: BaseRoomInfoProxyProtocol {
|
||||
@@ -70,12 +72,22 @@ struct RoomPreviewInfoProxy: BaseRoomInfoProxyProtocol {
|
||||
|
||||
var id: String { roomPreviewInfo.roomId }
|
||||
var displayName: String? { roomPreviewInfo.name }
|
||||
var avatar: RoomAvatar {
|
||||
.room(id: id, name: displayName, avatarURL: avatarURL)
|
||||
}
|
||||
|
||||
var heroes: [RoomHero] { roomPreviewInfo.heroes ?? [] }
|
||||
var topic: String? { roomPreviewInfo.topic }
|
||||
var canonicalAlias: String? { roomPreviewInfo.canonicalAlias }
|
||||
var avatarURL: URL? { roomPreviewInfo.avatarUrl.flatMap(URL.init) }
|
||||
var activeMembersCount: Int { Int(roomPreviewInfo.numJoinedMembers) }
|
||||
var isDirect: Bool { roomPreviewInfo.isDirect ?? false }
|
||||
var isSpace: Bool { roomPreviewInfo.roomType == .space }
|
||||
var activeMembersCount: Int { Int(roomPreviewInfo.numActiveMembers ?? roomPreviewInfo.numJoinedMembers) }
|
||||
|
||||
/// The room's avatar info for use in a ``RoomAvatarImage``.
|
||||
var avatar: RoomAvatar {
|
||||
if isDirect, avatarURL == nil {
|
||||
if heroes.count == 1 {
|
||||
return .heroes(heroes.map(UserProfileProxy.init))
|
||||
}
|
||||
}
|
||||
|
||||
return .room(id: id, name: displayName, avatarURL: avatarURL)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,9 @@ protocol RoomProxyProtocol {
|
||||
|
||||
// sourcery: AutoMockable
|
||||
protocol InvitedRoomProxyProtocol: RoomProxyProtocol {
|
||||
var info: RoomInfoProxy { get }
|
||||
var info: BaseRoomInfoProxyProtocol { get }
|
||||
var inviter: RoomMemberProxyProtocol? { get }
|
||||
func rejectInvitation() async -> Result<Void, RoomProxyError>
|
||||
func acceptInvitation() async -> Result<Void, RoomProxyError>
|
||||
}
|
||||
|
||||
// sourcery: AutoMockable
|
||||
|
||||
Reference in New Issue
Block a user