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

Fixes problems processing invites, build rooms differently based on their membership #3189

Merged
merged 2 commits into from
Aug 21, 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
2 changes: 1 addition & 1 deletion ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7657,7 +7657,7 @@
repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift";
requirement = {
kind = exactVersion;
version = 1.0.39;
version = 1.0.40;
};
};
701C7BEF8F70F7A83E852DCC /* XCRemoteSwiftPackageReference "GZIP" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/element-hq/matrix-rust-components-swift",
"state" : {
"revision" : "cdb8f594bfccf0c867bfa5a194c6972fd32a5502",
"version" : "1.0.39"
"revision" : "5d9f1865a71badfe6d9f7c3232b6cf23b12f8add",
"version" : "1.0.40"
}
},
{
Expand Down
205 changes: 205 additions & 0 deletions ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

var serverNameServerNameUnderlyingCallsCount = 0
Expand Down Expand Up @@ -15784,6 +15855,75 @@ open class RoomListItemSDKMock: MatrixRustSDK.RoomListItem {
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

var isDirectUnderlyingCallsCount = 0
Expand Down Expand Up @@ -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

open var roomInfoThrowableError: Error?
Expand Down
54 changes: 22 additions & 32 deletions ElementX/Sources/Services/Client/ClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -847,44 +847,34 @@ class ClientProxy: ClientProxyProtocol {

private func buildRoomForIdentifier(_ identifier: String) async -> RoomProxyType? {
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
}

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 {
try await roomListItem.initTimeline(eventTypeFilter: eventFilters, internalIdPrefix: nil)
} catch {
MXLog.error("Failed initializing room timeline with error: \(error)")
return nil
do {
let roomListItem = try roomListService.room(roomId: identifier)

switch roomListItem.membership() {
case .invited:
return try .invited(InvitedRoomProxy(roomListItem: roomListItem,
room: roomListItem.invitedRoom()))
case .joined:
if roomListItem.isTimelineInitialized() == false {
try await roomListItem.initTimeline(eventTypeFilter: eventFilters, internalIdPrefix: nil)
}

let roomProxy = try await JoinedRoomProxy(roomListService: roomListService,
roomListItem: roomListItem,
room: roomListItem.fullRoom())

return .joined(roomProxy)
case .left:
return .left
}
}

guard let room = try? roomListItem.fullRoom() else {
MXLog.error("Failed retrieving room, invalid room list item full room")
} catch {
MXLog.error("Failed retrieving room: \(identifier), with error: \(error)")
return nil
}

switch room.membership() {
case .invited:
return .invited(InvitedRoomProxy(roomListItem: roomListItem,
room: room))
case .joined:
guard let roomProxy = await JoinedRoomProxy(roomListService: roomListService,
roomListItem: roomListItem,
room: room) else {
return nil
}

return .joined(roomProxy)
case .left:
return .left
}
}

private func updateIgnoredUsers() {
Expand Down
13 changes: 4 additions & 9 deletions ElementX/Sources/Services/Room/JoinedRoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,14 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
room.activeRoomCallParticipants()
}

init?(roomListService: RoomListServiceProtocol,
roomListItem: RoomListItemProtocol,
room: RoomProtocol) async {
init(roomListService: RoomListServiceProtocol,
roomListItem: RoomListItemProtocol,
room: RoomProtocol) async throws {
self.roomListService = roomListService
self.roomListItem = roomListItem
self.room = room

do {
timeline = try await TimelineProxy(timeline: room.timeline(), isLive: true)
} catch {
MXLog.error("Failed creating timeline with error: \(error)")
return nil
}
timeline = try await TimelineProxy(timeline: room.timeline(), isLive: true)

Task {
await updateMembers()
Expand Down
2 changes: 1 addition & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ packages:
# Element/Matrix dependencies
MatrixRustSDK:
url: https://github.com/element-hq/matrix-rust-components-swift
exactVersion: 1.0.39
exactVersion: 1.0.40
# path: ../matrix-rust-sdk
Compound:
url: https://github.com/element-hq/compound-ios
Expand Down
Loading