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

using roomPreview API for invited rooms #3530

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
69 changes: 3 additions & 66 deletions ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions ElementX/Sources/Services/Client/ClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 13 additions & 21 deletions ElementX/Sources/Services/Room/InvitedRoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 3 additions & 4 deletions ElementX/Sources/Services/Room/KnockedRoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions ElementX/Sources/Services/Room/RoomInfoProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -70,12 +72,23 @@ struct RoomPreviewInfoProxy: BaseRoomInfoProxyProtocol {

var id: String { roomPreviewInfo.roomId }
var displayName: String? { roomPreviewInfo.name }

/// The room's avatar info for use in a ``RoomAvatarImage``.
var avatar: RoomAvatar {
// TODO: The heroes are missing so we can't handle the direct invite case yet, waiting for an update of the SDK
// if isDirect, avatarURL == nil {
// if heroes.count == 1 {
// return .heroes(heroes.map(UserProfileProxy.init))
// }
// }

.room(id: id, name: displayName, avatarURL: avatarURL)
}

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) }
}
4 changes: 2 additions & 2 deletions ElementX/Sources/Services/Room/RoomProxyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading