Skip to content

Commit

Permalink
Fix Rooms that user has knocked not displaying the request sent screen (
Browse files Browse the repository at this point in the history
#3513)

* fix knocked state

* pr suggestion

* code improvement
  • Loading branch information
Velin92 authored Nov 14, 2024
1 parent 9746da7 commit 2cb7fac
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 44 deletions.
50 changes: 29 additions & 21 deletions ElementX.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9569,11 +9569,11 @@ class KeychainControllerMock: KeychainControllerProtocol {
}
}
class KnockedRoomProxyMock: KnockedRoomProxyProtocol {
var info: RoomInfoProxy {
var info: BaseRoomInfoProxyProtocol {
get { return underlyingInfo }
set(value) { underlyingInfo = value }
}
var underlyingInfo: RoomInfoProxy!
var underlyingInfo: BaseRoomInfoProxyProtocol!
var id: String {
get { return underlyingId }
set(value) { underlyingId = value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,27 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
}

private func updateRoomDetails() {
var roomInfo: RoomInfoProxy?
var roomPreviewInfo: BaseRoomInfoProxyProtocol?
var inviter: RoomInviterDetails?

switch room {
case .joined(let joinedRoomProxy):
roomInfo = joinedRoomProxy.infoPublisher.value
roomPreviewInfo = joinedRoomProxy.infoPublisher.value
case .invited(let invitedRoomProxy):
inviter = invitedRoomProxy.info.inviter.flatMap(RoomInviterDetails.init)
roomInfo = invitedRoomProxy.info
roomPreviewInfo = invitedRoomProxy.info
case .knocked(let knockedRoomProxy):
roomInfo = knockedRoomProxy.info
roomPreviewInfo = knockedRoomProxy.info
default:
break
}

let name = roomInfo?.displayName ?? roomPreviewDetails?.name
let name = roomPreviewInfo?.displayName ?? roomPreviewDetails?.name
state.roomDetails = JoinRoomScreenRoomDetails(name: name,
topic: roomInfo?.topic ?? roomPreviewDetails?.topic,
canonicalAlias: roomInfo?.canonicalAlias ?? roomPreviewDetails?.canonicalAlias,
avatar: roomInfo?.avatar ?? .room(id: roomID, name: name ?? "", avatarURL: roomPreviewDetails?.avatarURL),
memberCount: UInt(roomInfo?.activeMembersCount ?? Int(roomPreviewDetails?.memberCount ?? 0)),
topic: roomPreviewInfo?.topic ?? roomPreviewDetails?.topic,
canonicalAlias: roomPreviewInfo?.canonicalAlias ?? roomPreviewDetails?.canonicalAlias,
avatar: roomPreviewInfo?.avatar ?? .room(id: roomID, name: name ?? "", avatarURL: roomPreviewDetails?.avatarURL),
memberCount: UInt(roomPreviewInfo?.activeMembersCount ?? Int(roomPreviewDetails?.memberCount ?? 0)),
inviter: inviter)

updateMode()
Expand Down
3 changes: 2 additions & 1 deletion ElementX/Sources/Services/Client/ClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,8 @@ class ClientProxy: ClientProxyProtocol {
case .knocked:
if appSettings.knockingEnabled {
return try await .knocked(KnockedRoomProxy(roomListItem: roomListItem,
room: roomListItem.invitedRoom()))
roomPreview: roomListItem.previewRoom(via: []),
ownUserID: userID))
} else {
return try await .invited(InvitedRoomProxy(roomListItem: roomListItem,
room: roomListItem.invitedRoom()))
Expand Down
19 changes: 10 additions & 9 deletions ElementX/Sources/Services/Room/KnockedRoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,27 @@ import UIKit

class KnockedRoomProxy: KnockedRoomProxyProtocol {
private let roomListItem: RoomListItemProtocol
private let room: RoomProtocol
private let roomPreview: RoomPreviewProtocol
let info: BaseRoomInfoProxyProtocol

// A room identifier is constant and lazy stops it from being fetched
// multiple times over FFI
lazy var id: String = room.id()
lazy var id = info.id

var ownUserID: String { room.ownUserId() }

let info: RoomInfoProxy
let ownUserID: String

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())
self.roomPreview = roomPreview
self.ownUserID = ownUserID
info = try RoomPreviewInfoProxy(roomPreviewInfo: roomPreview.info())
}

func cancelKnock() async -> Result<Void, RoomProxyError> {
do {
return try await .success(room.leave())
return try await .success(roomPreview.leave())
} catch {
MXLog.error("Failed cancelling the knock with error: \(error)")
return .failure(.sdkError(error))
Expand Down
27 changes: 26 additions & 1 deletion ElementX/Sources/Services/Room/RoomInfoProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@
import Foundation
import MatrixRustSDK

struct RoomInfoProxy {
protocol BaseRoomInfoProxyProtocol {
var id: String { get }
var displayName: String? { get }
var avatar: RoomAvatar { get }
var topic: String? { get }
var canonicalAlias: String? { get }
var avatarURL: URL? { get }
var activeMembersCount: Int { get }
}

struct RoomInfoProxy: BaseRoomInfoProxyProtocol {
let roomInfo: RoomInfo

var id: String { roomInfo.id }
Expand Down Expand Up @@ -54,3 +64,18 @@ struct RoomInfoProxy {
var unreadMentionsCount: UInt { UInt(roomInfo.numUnreadMentions) }
var pinnedEventIDs: Set<String> { Set(roomInfo.pinnedEventIds) }
}

struct RoomPreviewInfoProxy: BaseRoomInfoProxyProtocol {
let roomPreviewInfo: RoomPreviewInfo

var id: String { roomPreviewInfo.roomId }
var displayName: String? { roomPreviewInfo.name }
var avatar: RoomAvatar {
.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) }
}
2 changes: 1 addition & 1 deletion ElementX/Sources/Services/Room/RoomProxyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protocol InvitedRoomProxyProtocol: RoomProxyProtocol {

// sourcery: AutoMockable
protocol KnockedRoomProxyProtocol: RoomProxyProtocol {
var info: RoomInfoProxy { get }
var info: BaseRoomInfoProxyProtocol { get }
func cancelKnock() async -> Result<Void, RoomProxyError>
}

Expand Down

0 comments on commit 2cb7fac

Please sign in to comment.