Skip to content

Commit

Permalink
update SDK and added logic to display the banner
Browse files Browse the repository at this point in the history
in the room screen
  • Loading branch information
Velin92 committed Nov 22, 2024
1 parent 9535140 commit 7b21add
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8195,7 +8195,7 @@
repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift";
requirement = {
kind = exactVersion;
version = 1.0.73;
version = 1.0.74;
};
};
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" : "b3f97292695e8d63469c0d3ec608eb74423c6a2e",
"version" : "1.0.73"
"revision" : "66d32e79ae20dd31201cd16eced53cfcc0c3239d",
"version" : "1.0.74"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ struct KnockRequestsListScreenViewState: BindableState {
var canAccept = true
var canDecline = true
var canBan = true
var isKnockRoom = true
var isKnockableRoom = true

// If all the permissions are denied or the join rule changes while we are in the view
// we want to stop displaying any request
var shouldDisplayRequests: Bool {
!requests.isEmpty && isKnockRoom && (canAccept || canDecline || canBan)
!requests.isEmpty && isKnockableRoom && (canAccept || canDecline || canBan)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class KnockRequestsListScreenViewModel: KnockRequestsListScreenViewModelType, Kn

private func setupSubscriptions() {
roomProxy.infoPublisher
.throttle(for: .milliseconds(200), scheduler: DispatchQueue.main, latest: true)
.receive(on: DispatchQueue.main)
.sink { [weak self] roomInfo in
self?.updateRoomInfo(roomInfo: roomInfo)
Task { await self?.updatePermissions() }
Expand All @@ -60,9 +60,9 @@ class KnockRequestsListScreenViewModel: KnockRequestsListScreenViewModelType, Kn
private func updateRoomInfo(roomInfo: RoomInfoProxy) {
switch roomInfo.joinRule {
case .knock, .knockRestricted:
state.isKnockRoom = true
state.isKnockableRoom = true
default:
state.isKnockRoom = false
state.isKnockableRoom = false
}
}

Expand Down
12 changes: 12 additions & 0 deletions ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
var unseenKnockRequests: [KnockRequestInfo] = []

var shouldSeeKnockRequests: Bool {
isKnockingEnabled && isKnockableRoom && !unseenKnockRequests.isEmpty && (canAcceptKnocks || canDeclineKnocks || canBan)
}

var footerDetails: RoomScreenFooterViewDetails?

var bindings: RoomScreenViewStateBindings
Expand Down
13 changes: 13 additions & 0 deletions ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -240,6 +244,15 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
if case let .success(permission) = await roomProxy.canUserJoinCall(userID: userID) {
state.canJoinCall = permission
}
state.canAcceptKnocks = await (try? roomProxy.canUserInvite(userID: roomProxy.ownUserID).get()) == true
state.canDeclineKnocks = await (try? roomProxy.canUserKick(userID: roomProxy.ownUserID).get()) == true
state.canBan = await (try? roomProxy.canUserBan(userID: roomProxy.ownUserID).get()) == true
switch roomInfo.joinRule {
case .knock, .knockRestricted:
state.isKnockableRoom = true
default:
state.isKnockableRoom = false
}
}

private func setupPinnedEventsTimelineProviderIfNeeded() {
Expand Down
2 changes: 1 addition & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ packages:
# Element/Matrix dependencies
MatrixRustSDK:
url: https://github.com/element-hq/matrix-rust-components-swift
exactVersion: 1.0.73
exactVersion: 1.0.74
# path: ../matrix-rust-sdk
Compound:
url: https://github.com/element-hq/compound-ios
Expand Down

0 comments on commit 7b21add

Please sign in to comment.