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

Use both the room list room and the room preview details to populate the join room screen #3062

Merged
merged 1 commit into from
Jul 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ enum JoinRoomScreenInteractionMode {
case knock
}

struct JoinRoomScreenRoomDetails {
let name: String?
let topic: String?
let canonicalAlias: String?
let avatar: RoomAvatar
let memberCount: UInt
}

struct JoinRoomScreenViewState: BindableState {
// Maybe use room summary details or similar here??
let roomID: String

var roomDetails: RoomPreviewDetails?
var roomDetails: JoinRoomScreenRoomDetails?

var mode: JoinRoomScreenInteractionMode = .loading

Expand All @@ -52,7 +60,7 @@ struct JoinRoomScreenViewState: BindableState {
}

var avatar: RoomAvatar {
.room(id: roomID, name: title, avatarURL: roomDetails?.avatarURL)
roomDetails?.avatar ?? .room(id: roomID, name: title, avatarURL: nil)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
private let clientProxy: ClientProxyProtocol
private let userIndicatorController: UserIndicatorControllerProtocol

private var roomPreviewDetails: RoomPreviewDetails?
private var roomProxy: RoomProxyProtocol?

private let actionsSubject: PassthroughSubject<JoinRoomScreenViewModelAction, Never> = .init()
var actionsPublisher: AnyPublisher<JoinRoomScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
Expand Down Expand Up @@ -77,31 +80,56 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
showLoadingIndicator()

defer {
updateMode()
hideLoadingIndicator()
}

// Using only the preview API isn't enough as it's not capable
// of giving us information for non-joined rooms (at least not on synapse)
// See if we known about the room locally and, if so, have that
// take priority over the preview one.

if let roomProxy = await clientProxy.roomForIdentifier(roomID) {
self.roomProxy = roomProxy
updateRoomDetails()
}

switch await clientProxy.roomPreviewForIdentifier(roomID, via: via) {
case .success(let roomDetails):
state.roomDetails = roomDetails
case .success(let roomPreviewDetails):
self.roomPreviewDetails = roomPreviewDetails
updateRoomDetails()
case .failure(.roomPreviewIsPrivate):
break // Handled by the mode, we don't need an error indicator.
case .failure:
userIndicatorController.submitIndicator(UserIndicator(title: L10n.errorUnknown))
}
}

private func updateRoomDetails() {
if roomProxy == nil, roomPreviewDetails == nil {
return
}

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

updateMode()
}

private func updateMode() {
guard let roomDetails = state.roomDetails else {
if roomProxy == nil, roomPreviewDetails == nil {
state.mode = .unknown
return
}

if roomDetails.isPublic {
if roomProxy?.isPublic ?? false || roomPreviewDetails?.isPublic ?? false {
state.mode = .join
} else if roomDetails.isInvited {
} else if roomProxy?.membership == .invited || roomPreviewDetails?.isInvited ?? false {
state.mode = .invited
} else if roomDetails.canKnock, allowKnocking { // Knocking is not supported yet, the flag is purely for preview tests.
} else if roomPreviewDetails?.canKnock ?? false, allowKnocking { // Knocking is not supported yet, the flag is purely for preview tests.
state.mode = .knock
} else {
state.mode = .unknown
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading