mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Knock Requests banner display logic (#3550)
* added the join rule to the info * update SDK and added logic to display the banner in the room screen * added the logic to display the banner
This commit is contained in:
@@ -39,6 +39,18 @@ struct RoomScreenViewState: BindableState {
|
||||
var hasOngoingCall: Bool
|
||||
var shouldShowCallButton = true
|
||||
|
||||
var isKnockingEnabled = false
|
||||
var isKnockableRoom = false
|
||||
var canAcceptKnocks = false
|
||||
var canDeclineKnocks = false
|
||||
var canBan = false
|
||||
// TODO: We still don't know how to get these, but these will be the non already seen knock requests of the room, for now we are using this as a mock for testing purposes
|
||||
var unseenKnockRequests: [KnockRequestInfo] = [.init(displayName: "Alice", avatarURL: nil, userID: "@alice:matrix.org", reason: "Helloooo")]
|
||||
|
||||
var shouldSeeKnockRequests: Bool {
|
||||
isKnockingEnabled && isKnockableRoom && !unseenKnockRequests.isEmpty && (canAcceptKnocks || canDeclineKnocks || canBan)
|
||||
}
|
||||
|
||||
var footerDetails: RoomScreenFooterViewDetails?
|
||||
|
||||
var bindings: RoomScreenViewStateBindings
|
||||
|
||||
@@ -117,6 +117,10 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
||||
// MARK: - Private
|
||||
|
||||
private func setupSubscriptions(ongoingCallRoomIDPublisher: CurrentValuePublisher<String?, Never>) {
|
||||
appSettings.$knockingEnabled
|
||||
.weakAssign(to: \.state.isKnockingEnabled, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
let roomInfoSubscription = roomProxy
|
||||
.infoPublisher
|
||||
|
||||
@@ -236,10 +240,18 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
||||
state.pinnedEventsBannerState = .loading(numbersOfEvents: pinnedEventIDs.count)
|
||||
}
|
||||
|
||||
let userID = roomProxy.ownUserID
|
||||
if case let .success(permission) = await roomProxy.canUserJoinCall(userID: userID) {
|
||||
state.canJoinCall = permission
|
||||
switch (roomProxy.isEncryptedOneToOneRoom, roomInfo.joinRule) {
|
||||
case (false, .knock), (false, .knockRestricted):
|
||||
state.isKnockableRoom = true
|
||||
default:
|
||||
state.isKnockableRoom = false
|
||||
}
|
||||
|
||||
let ownUserID = roomProxy.ownUserID
|
||||
state.canJoinCall = await (try? roomProxy.canUserJoinCall(userID: ownUserID).get()) == true
|
||||
state.canAcceptKnocks = await (try? roomProxy.canUserInvite(userID: ownUserID).get()) == true
|
||||
state.canDeclineKnocks = await (try? roomProxy.canUserKick(userID: ownUserID).get()) == true
|
||||
state.canBan = await (try? roomProxy.canUserBan(userID: ownUserID).get()) == true
|
||||
}
|
||||
|
||||
private func setupPinnedEventsTimelineProviderIfNeeded() {
|
||||
|
||||
@@ -29,12 +29,11 @@ struct RoomScreen: View {
|
||||
timeline
|
||||
.background(Color.compound.bgCanvasDefault.ignoresSafeArea())
|
||||
.overlay(alignment: .top) {
|
||||
Group {
|
||||
if roomContext.viewState.shouldShowPinnedEventsBanner {
|
||||
pinnedItemsBanner
|
||||
}
|
||||
}
|
||||
.animation(.elementDefault, value: roomContext.viewState.shouldShowPinnedEventsBanner)
|
||||
pinnedItemsBanner
|
||||
}
|
||||
// This can overlay on top of the pinnedItemsBanner
|
||||
.overlay(alignment: .top) {
|
||||
knockRequestsBanner
|
||||
}
|
||||
.safeAreaInset(edge: .bottom, spacing: 0) {
|
||||
VStack(spacing: 0) {
|
||||
@@ -119,11 +118,45 @@ struct RoomScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var pinnedItemsBanner: some View {
|
||||
PinnedItemsBannerView(state: roomContext.viewState.pinnedEventsBannerState,
|
||||
onMainButtonTap: { roomContext.send(viewAction: .tappedPinnedEventsBanner) },
|
||||
onViewAllButtonTap: { roomContext.send(viewAction: .viewAllPins) })
|
||||
.transition(.move(edge: .top))
|
||||
Group {
|
||||
if roomContext.viewState.shouldShowPinnedEventsBanner {
|
||||
PinnedItemsBannerView(state: roomContext.viewState.pinnedEventsBannerState,
|
||||
onMainButtonTap: { roomContext.send(viewAction: .tappedPinnedEventsBanner) },
|
||||
onViewAllButtonTap: { roomContext.send(viewAction: .viewAllPins) })
|
||||
.transition(.move(edge: .top))
|
||||
}
|
||||
}
|
||||
.animation(.elementDefault, value: roomContext.viewState.shouldShowPinnedEventsBanner)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var knockRequestsBanner: some View {
|
||||
Group {
|
||||
if roomContext.viewState.shouldSeeKnockRequests {
|
||||
KnockRequestsBannerView(requests: roomContext.viewState.unseenKnockRequests,
|
||||
onDismiss: dismissKnockRequestsBanner,
|
||||
onAccept: roomContext.viewState.canAcceptKnocks ? acceptKnockRequest : nil,
|
||||
onViewAll: onViewAllKnockRequests,
|
||||
mediaProvider: roomContext.mediaProvider)
|
||||
.padding(.top, 16)
|
||||
.transition(.move(edge: .top))
|
||||
}
|
||||
}
|
||||
.animation(.elementDefault, value: roomContext.viewState.shouldSeeKnockRequests)
|
||||
}
|
||||
|
||||
private func dismissKnockRequestsBanner() {
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
private func acceptKnockRequest(userID: String) {
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
private func onViewAllKnockRequests() {
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
private var scrollToBottomButton: some View {
|
||||
|
||||
Reference in New Issue
Block a user