mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-06 04:18:31 +00:00
Fixes problems processing invites, build rooms differently based on their membership
This commit is contained in:
committed by
Stefan Ceriu
parent
e281a3f242
commit
404b78e7c7
@@ -4591,6 +4591,77 @@ open class ClientBuilderSDKMock: MatrixRustSDK.ClientBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//MARK: - roomKeyRecipientStrategy
|
||||||
|
|
||||||
|
var roomKeyRecipientStrategyStrategyUnderlyingCallsCount = 0
|
||||||
|
open var roomKeyRecipientStrategyStrategyCallsCount: Int {
|
||||||
|
get {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
return roomKeyRecipientStrategyStrategyUnderlyingCallsCount
|
||||||
|
} else {
|
||||||
|
var returnValue: Int? = nil
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
returnValue = roomKeyRecipientStrategyStrategyUnderlyingCallsCount
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
roomKeyRecipientStrategyStrategyUnderlyingCallsCount = newValue
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
roomKeyRecipientStrategyStrategyUnderlyingCallsCount = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
open var roomKeyRecipientStrategyStrategyCalled: Bool {
|
||||||
|
return roomKeyRecipientStrategyStrategyCallsCount > 0
|
||||||
|
}
|
||||||
|
open var roomKeyRecipientStrategyStrategyReceivedStrategy: CollectStrategy?
|
||||||
|
open var roomKeyRecipientStrategyStrategyReceivedInvocations: [CollectStrategy] = []
|
||||||
|
|
||||||
|
var roomKeyRecipientStrategyStrategyUnderlyingReturnValue: ClientBuilder!
|
||||||
|
open var roomKeyRecipientStrategyStrategyReturnValue: ClientBuilder! {
|
||||||
|
get {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
return roomKeyRecipientStrategyStrategyUnderlyingReturnValue
|
||||||
|
} else {
|
||||||
|
var returnValue: ClientBuilder? = nil
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
returnValue = roomKeyRecipientStrategyStrategyUnderlyingReturnValue
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
roomKeyRecipientStrategyStrategyUnderlyingReturnValue = newValue
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
roomKeyRecipientStrategyStrategyUnderlyingReturnValue = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
open var roomKeyRecipientStrategyStrategyClosure: ((CollectStrategy) -> ClientBuilder)?
|
||||||
|
|
||||||
|
open override func roomKeyRecipientStrategy(strategy: CollectStrategy) -> ClientBuilder {
|
||||||
|
roomKeyRecipientStrategyStrategyCallsCount += 1
|
||||||
|
roomKeyRecipientStrategyStrategyReceivedStrategy = strategy
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.roomKeyRecipientStrategyStrategyReceivedInvocations.append(strategy)
|
||||||
|
}
|
||||||
|
if let roomKeyRecipientStrategyStrategyClosure = roomKeyRecipientStrategyStrategyClosure {
|
||||||
|
return roomKeyRecipientStrategyStrategyClosure(strategy)
|
||||||
|
} else {
|
||||||
|
return roomKeyRecipientStrategyStrategyReturnValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//MARK: - serverName
|
//MARK: - serverName
|
||||||
|
|
||||||
var serverNameServerNameUnderlyingCallsCount = 0
|
var serverNameServerNameUnderlyingCallsCount = 0
|
||||||
@@ -15784,6 +15855,75 @@ open class RoomListItemSDKMock: MatrixRustSDK.RoomListItem {
|
|||||||
try await initTimelineEventTypeFilterInternalIdPrefixClosure?(eventTypeFilter, internalIdPrefix)
|
try await initTimelineEventTypeFilterInternalIdPrefixClosure?(eventTypeFilter, internalIdPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//MARK: - invitedRoom
|
||||||
|
|
||||||
|
open var invitedRoomThrowableError: Error?
|
||||||
|
var invitedRoomUnderlyingCallsCount = 0
|
||||||
|
open var invitedRoomCallsCount: Int {
|
||||||
|
get {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
return invitedRoomUnderlyingCallsCount
|
||||||
|
} else {
|
||||||
|
var returnValue: Int? = nil
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
returnValue = invitedRoomUnderlyingCallsCount
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
invitedRoomUnderlyingCallsCount = newValue
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
invitedRoomUnderlyingCallsCount = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
open var invitedRoomCalled: Bool {
|
||||||
|
return invitedRoomCallsCount > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var invitedRoomUnderlyingReturnValue: Room!
|
||||||
|
open var invitedRoomReturnValue: Room! {
|
||||||
|
get {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
return invitedRoomUnderlyingReturnValue
|
||||||
|
} else {
|
||||||
|
var returnValue: Room? = nil
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
returnValue = invitedRoomUnderlyingReturnValue
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
invitedRoomUnderlyingReturnValue = newValue
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
invitedRoomUnderlyingReturnValue = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
open var invitedRoomClosure: (() throws -> Room)?
|
||||||
|
|
||||||
|
open override func invitedRoom() throws -> Room {
|
||||||
|
if let error = invitedRoomThrowableError {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
invitedRoomCallsCount += 1
|
||||||
|
if let invitedRoomClosure = invitedRoomClosure {
|
||||||
|
return try invitedRoomClosure()
|
||||||
|
} else {
|
||||||
|
return invitedRoomReturnValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//MARK: - isDirect
|
//MARK: - isDirect
|
||||||
|
|
||||||
var isDirectUnderlyingCallsCount = 0
|
var isDirectUnderlyingCallsCount = 0
|
||||||
@@ -16044,6 +16184,71 @@ open class RoomListItemSDKMock: MatrixRustSDK.RoomListItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//MARK: - membership
|
||||||
|
|
||||||
|
var membershipUnderlyingCallsCount = 0
|
||||||
|
open var membershipCallsCount: Int {
|
||||||
|
get {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
return membershipUnderlyingCallsCount
|
||||||
|
} else {
|
||||||
|
var returnValue: Int? = nil
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
returnValue = membershipUnderlyingCallsCount
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
membershipUnderlyingCallsCount = newValue
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
membershipUnderlyingCallsCount = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
open var membershipCalled: Bool {
|
||||||
|
return membershipCallsCount > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var membershipUnderlyingReturnValue: Membership!
|
||||||
|
open var membershipReturnValue: Membership! {
|
||||||
|
get {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
return membershipUnderlyingReturnValue
|
||||||
|
} else {
|
||||||
|
var returnValue: Membership? = nil
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
returnValue = membershipUnderlyingReturnValue
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
membershipUnderlyingReturnValue = newValue
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
membershipUnderlyingReturnValue = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
open var membershipClosure: (() -> Membership)?
|
||||||
|
|
||||||
|
open override func membership() -> Membership {
|
||||||
|
membershipCallsCount += 1
|
||||||
|
if let membershipClosure = membershipClosure {
|
||||||
|
return membershipClosure()
|
||||||
|
} else {
|
||||||
|
return membershipReturnValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//MARK: - roomInfo
|
//MARK: - roomInfo
|
||||||
|
|
||||||
open var roomInfoThrowableError: Error?
|
open var roomInfoThrowableError: Error?
|
||||||
|
|||||||
@@ -847,44 +847,34 @@ class ClientProxy: ClientProxyProtocol {
|
|||||||
|
|
||||||
private func buildRoomForIdentifier(_ identifier: String) async -> RoomProxyType? {
|
private func buildRoomForIdentifier(_ identifier: String) async -> RoomProxyType? {
|
||||||
guard let roomListService else {
|
guard let roomListService else {
|
||||||
MXLog.error("Failed retrieving room, room list service not set up")
|
MXLog.error("Failed retrieving room: \(identifier), room list service not set up")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let roomListItem = try? roomListService.room(roomId: identifier) else {
|
|
||||||
MXLog.error("Failed retrieving room, invalid room list item")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if roomListItem.isTimelineInitialized() == false {
|
|
||||||
do {
|
do {
|
||||||
try await roomListItem.initTimeline(eventTypeFilter: eventFilters, internalIdPrefix: nil)
|
let roomListItem = try roomListService.room(roomId: identifier)
|
||||||
} catch {
|
|
||||||
MXLog.error("Failed initializing room timeline with error: \(error)")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
guard let room = try? roomListItem.fullRoom() else {
|
switch roomListItem.membership() {
|
||||||
MXLog.error("Failed retrieving room, invalid room list item full room")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
switch room.membership() {
|
|
||||||
case .invited:
|
case .invited:
|
||||||
return .invited(InvitedRoomProxy(roomListItem: roomListItem,
|
return try .invited(InvitedRoomProxy(roomListItem: roomListItem,
|
||||||
room: room))
|
room: roomListItem.invitedRoom()))
|
||||||
case .joined:
|
case .joined:
|
||||||
guard let roomProxy = await JoinedRoomProxy(roomListService: roomListService,
|
if roomListItem.isTimelineInitialized() == false {
|
||||||
roomListItem: roomListItem,
|
try await roomListItem.initTimeline(eventTypeFilter: eventFilters, internalIdPrefix: nil)
|
||||||
room: room) else {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let roomProxy = try await JoinedRoomProxy(roomListService: roomListService,
|
||||||
|
roomListItem: roomListItem,
|
||||||
|
room: roomListItem.fullRoom())
|
||||||
|
|
||||||
return .joined(roomProxy)
|
return .joined(roomProxy)
|
||||||
case .left:
|
case .left:
|
||||||
return .left
|
return .left
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
MXLog.error("Failed retrieving room: \(identifier), with error: \(error)")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateIgnoredUsers() {
|
private func updateIgnoredUsers() {
|
||||||
|
|||||||
@@ -165,19 +165,14 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
|||||||
room.activeRoomCallParticipants()
|
room.activeRoomCallParticipants()
|
||||||
}
|
}
|
||||||
|
|
||||||
init?(roomListService: RoomListServiceProtocol,
|
init(roomListService: RoomListServiceProtocol,
|
||||||
roomListItem: RoomListItemProtocol,
|
roomListItem: RoomListItemProtocol,
|
||||||
room: RoomProtocol) async {
|
room: RoomProtocol) async throws {
|
||||||
self.roomListService = roomListService
|
self.roomListService = roomListService
|
||||||
self.roomListItem = roomListItem
|
self.roomListItem = roomListItem
|
||||||
self.room = room
|
self.room = room
|
||||||
|
|
||||||
do {
|
|
||||||
timeline = try await TimelineProxy(timeline: room.timeline(), isLive: true)
|
timeline = try await TimelineProxy(timeline: room.timeline(), isLive: true)
|
||||||
} catch {
|
|
||||||
MXLog.error("Failed creating timeline with error: \(error)")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
await updateMembers()
|
await updateMembers()
|
||||||
|
|||||||
Reference in New Issue
Block a user