Knocked Preview implementation (#3426)

* JoinRoomScreen ui for knocking

* code improvement

* updated previews

* added knocked state with tests

* send knock request

* Apply suggestions from code review

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>

* pr comments

* update tests

* new API

* knock implementation and cancel knock

* update strings

* added a knocked cell in the home screen

* design update

* updated SDK

* simplified the invite case code

* pr comments

* updated previews

* added message as reason

* updated strings

* fixing tests

---------

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
This commit is contained in:
Mauro
2024-10-24 17:23:06 +02:00
committed by GitHub
parent 7d373c07a3
commit 2511c98090
48 changed files with 492 additions and 120 deletions
@@ -59,8 +59,7 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
case .declineInvite:
showDeclineInviteConfirmationAlert()
case .cancelKnock:
// TODO: implement once available
break
showCancelKnockConfirmationAlert()
}
}
@@ -78,15 +77,7 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
Task { await updateRoomDetails() }
}
// 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 room = await clientProxy.roomForIdentifier(roomID) {
self.room = room
await updateRoomDetails()
}
await updateRoom()
switch await clientProxy.roomPreviewForIdentifier(roomID, via: via) {
case .success(let roomPreviewDetails):
@@ -99,6 +90,17 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
}
}
private func updateRoom() async {
// 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 room = await clientProxy.roomForIdentifier(roomID) {
self.room = room
await updateRoomDetails()
}
}
private func updateRoomDetails() async {
var roomProxy: RoomProxyProtocol?
var inviter: RoomInviterDetails?
@@ -188,7 +190,8 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
switch await clientProxy.knockRoomAlias(alias,
message: state.bindings.knockMessage.isBlank ? nil : state.bindings.knockMessage) {
case .success:
state.mode = .knocked
// The room should become knocked through the sync
await updateRoom()
case .failure(let error):
MXLog.error("Failed knocking room alias: \(alias) with error: \(error)")
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
@@ -198,7 +201,8 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
via: via,
message: state.bindings.knockMessage.isBlank ? nil : state.bindings.knockMessage) {
case .success:
state.mode = .knocked
// The room should become knocked through the sync
await updateRoom()
case .failure(let error):
MXLog.error("Failed knocking room id: \(roomID) with error: \(error)")
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
@@ -220,6 +224,14 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
secondaryButton: .init(title: L10n.actionDecline, role: .destructive, action: { Task { await self.declineInvite() } }))
}
private func showCancelKnockConfirmationAlert() {
state.bindings.alertInfo = .init(id: .cancelKnock,
title: L10n.screenJoinRoomCancelKnockAlertTitle,
message: L10n.screenJoinRoomCancelKnockAlertDescription,
primaryButton: .init(title: L10n.actionNo, role: .cancel, action: nil),
secondaryButton: .init(title: L10n.screenJoinRoomCancelKnockAlertConfirmation, role: .destructive, action: { Task { await self.cancelKnock() } }))
}
private func declineInvite() async {
defer {
userIndicatorController.retractIndicatorWithId(roomID)
@@ -236,6 +248,29 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
if case .failure = result {
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
} else {
actionsSubject.send(.dismiss)
}
}
private func cancelKnock() async {
defer {
userIndicatorController.retractIndicatorWithId(roomID)
}
userIndicatorController.submitIndicator(UserIndicator(id: roomID, type: .modal, title: L10n.commonLoading, persistent: true))
guard case let .knocked(roomProxy) = room else {
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
return
}
let result = await roomProxy.cancelKnock()
if case .failure = result {
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
} else {
actionsSubject.send(.dismiss)
}
}