Adopt room info power levels (#4245)

* Use the newly RoomInfo published PowerLevels; update permissions at the same time as the room info and avoid unnecessary async calls.

* Introduce a RoomInfoProxyProtocol and associated mock and move away from mocked SDK RoomInfos

* Bump the SDK to v25.06.23

* Expose new non-throwing methods for checking one's own user permissions

* Fix the unit and preview tests (except the TimelineMediaPreviewDetails for which simplified snapshots were generated)

* Converge on one single implementation for computing a room's avatar.

* Fix more unit tests

* Fix the TimelineMediaPreviewDetailsView snapshot tests

This reverts commit 9b6c819e611ad2fa3de2c34a4a7aa556fc9faadd.

---------

Co-authored-by: Doug <douglase@element.io>
This commit is contained in:
Stefan Ceriu
2025-06-24 19:48:00 +03:00
committed by GitHub
parent f0e653e462
commit e5a49c568f
31 changed files with 1274 additions and 362 deletions

View File

@@ -355,14 +355,24 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
func testCanEditAvatar() async {
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, isPublic: false, members: mockedMembers))
let powerLevelsMock = RoomPowerLevelsProxyMock(configuration: .init())
roomProxyMock.powerLevelsReturnValue = .success(powerLevelsMock)
let configuration = JoinedRoomProxyMockConfiguration(name: "Test",
isDirect: false,
isPublic: false,
members: mockedMembers)
powerLevelsMock.canUserUserIDSendStateEventClosure = { _, event in
roomProxyMock = JoinedRoomProxyMock(configuration)
let powerLevelsProxyMock = RoomPowerLevelsProxyMock(configuration: .init())
powerLevelsProxyMock.canUserUserIDSendStateEventClosure = { _, event in
.success(event == .roomAvatar)
}
roomProxyMock.powerLevelsReturnValue = .success(powerLevelsProxyMock)
let roomInfoProxyMock = RoomInfoProxyMock(configuration)
roomInfoProxyMock.powerLevels = powerLevelsProxyMock
roomProxyMock.infoPublisher = CurrentValueSubject(roomInfoProxyMock).asCurrentValuePublisher()
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
clientProxy: ClientProxyMock(.init()),
mediaProvider: MediaProviderMock(configuration: .init()),
@@ -383,14 +393,24 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
func testCanEditName() async {
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, isPublic: false, members: mockedMembers))
let powerLevelsMock = RoomPowerLevelsProxyMock(configuration: .init())
roomProxyMock.powerLevelsReturnValue = .success(powerLevelsMock)
let configuration = JoinedRoomProxyMockConfiguration(name: "Test",
isDirect: false,
isPublic: false,
members: mockedMembers)
powerLevelsMock.canUserUserIDSendStateEventClosure = { _, event in
roomProxyMock = JoinedRoomProxyMock(configuration)
let powerLevelsProxyMock = RoomPowerLevelsProxyMock(configuration: .init())
powerLevelsProxyMock.canUserUserIDSendStateEventClosure = { _, event in
.success(event == .roomName)
}
roomProxyMock.powerLevelsReturnValue = .success(powerLevelsProxyMock)
let roomInfoProxyMock = RoomInfoProxyMock(configuration)
roomInfoProxyMock.powerLevels = powerLevelsProxyMock
roomProxyMock.infoPublisher = CurrentValueSubject(roomInfoProxyMock).asCurrentValuePublisher()
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
clientProxy: ClientProxyMock(.init()),
mediaProvider: MediaProviderMock(configuration: .init()),
@@ -411,14 +431,24 @@ class RoomDetailsScreenViewModelTests: XCTestCase {
func testCanEditTopic() async {
let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice]
roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, isPublic: false, members: mockedMembers))
let powerLevelsMock = RoomPowerLevelsProxyMock(configuration: .init())
roomProxyMock.powerLevelsReturnValue = .success(powerLevelsMock)
let configuration = JoinedRoomProxyMockConfiguration(name: "Test",
isDirect: false,
isPublic: false,
members: mockedMembers)
powerLevelsMock.canUserUserIDSendStateEventClosure = { _, event in
roomProxyMock = JoinedRoomProxyMock(configuration)
let powerLevelsProxyMock = RoomPowerLevelsProxyMock(configuration: .init())
powerLevelsProxyMock.canUserUserIDSendStateEventClosure = { _, event in
.success(event == .roomTopic)
}
roomProxyMock.powerLevelsReturnValue = .success(powerLevelsProxyMock)
let roomInfoProxyMock = RoomInfoProxyMock(configuration)
roomInfoProxyMock.powerLevels = powerLevelsProxyMock
roomProxyMock.infoPublisher = CurrentValueSubject(roomInfoProxyMock).asCurrentValuePublisher()
viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock,
clientProxy: ClientProxyMock(.init()),
mediaProvider: MediaProviderMock(configuration: .init()),

View File

@@ -274,7 +274,7 @@ class RoomFlowCoordinatorTests: XCTestCase {
var configuration = JoinedRoomProxyMockConfiguration()
let roomProxy = JoinedRoomProxyMock(configuration)
let roomInfoSubject = CurrentValueSubject<RoomInfoProxy, Never>(.init(roomInfo: .init(configuration)))
let roomInfoSubject = CurrentValueSubject<RoomInfoProxyProtocol, Never>(RoomInfoProxyMock(configuration))
roomProxy.infoPublisher = roomInfoSubject.asCurrentValuePublisher()
clientProxy.roomForIdentifierClosure = { _ in
@@ -288,7 +288,7 @@ class RoomFlowCoordinatorTests: XCTestCase {
}
configuration.membership = .left
roomInfoSubject.send(.init(roomInfo: .init(configuration)))
roomInfoSubject.send(RoomInfoProxyMock(configuration))
try await fulfillment.fulfill()
}

View File

@@ -26,7 +26,7 @@ class RoomScreenViewModelTests: XCTestCase {
func testPinnedEventsBanner() async throws {
var configuration = JoinedRoomProxyMockConfiguration()
let timelineSubject = PassthroughSubject<TimelineProxyProtocol, Never>()
let infoSubject = CurrentValueSubject<RoomInfoProxy, Never>(.init(roomInfo: RoomInfo(configuration)))
let infoSubject = CurrentValueSubject<RoomInfoProxyProtocol, Never>(RoomInfoProxyMock(configuration))
let roomProxyMock = JoinedRoomProxyMock(configuration)
// setup a way to inject the mock of the pinned events timeline
roomProxyMock.pinnedEventsTimelineClosure = {
@@ -63,7 +63,7 @@ class RoomScreenViewModelTests: XCTestCase {
viewState.pinnedEventsBannerState.count == 2
}
configuration.pinnedEventIDs = ["test1", "test2"]
infoSubject.send(.init(roomInfo: RoomInfo(configuration)))
infoSubject.send(RoomInfoProxyMock(configuration))
try await deferred.fulfill()
XCTAssertTrue(viewModel.context.viewState.pinnedEventsBannerState.isLoading)
XCTAssertTrue(viewModel.context.viewState.shouldShowPinnedEventsBanner)
@@ -165,7 +165,7 @@ class RoomScreenViewModelTests: XCTestCase {
func testRoomInfoUpdate() async throws {
var configuration = JoinedRoomProxyMockConfiguration(id: "TestID", name: "StartingName", avatarURL: nil, hasOngoingCall: false)
let infoSubject = CurrentValueSubject<RoomInfoProxy, Never>(.init(roomInfo: RoomInfo(configuration)))
let infoSubject = CurrentValueSubject<RoomInfoProxyProtocol, Never>(RoomInfoProxyMock(configuration))
let roomProxyMock = JoinedRoomProxyMock(configuration)
let powerLevelsMock = RoomPowerLevelsProxyMock(configuration: .init())
@@ -206,7 +206,7 @@ class RoomScreenViewModelTests: XCTestCase {
viewState.hasOngoingCall
}
infoSubject.send(.init(roomInfo: RoomInfo(configuration)))
infoSubject.send(RoomInfoProxyMock(configuration))
try await deferred.fulfill()
}

View File

@@ -468,7 +468,7 @@ class TimelineViewModelTests: XCTestCase {
var configuration = JoinedRoomProxyMockConfiguration(name: "",
pinnedEventIDs: .init(["test1"]))
let roomProxyMock = JoinedRoomProxyMock(configuration)
let infoSubject = CurrentValueSubject<RoomInfoProxy, Never>(.init(roomInfo: RoomInfo(configuration)))
let infoSubject = CurrentValueSubject<RoomInfoProxyProtocol, Never>(RoomInfoProxyMock(configuration))
roomProxyMock.underlyingInfoPublisher = infoSubject.asCurrentValuePublisher()
let viewModel = TimelineViewModel(roomProxy: roomProxyMock,
@@ -489,7 +489,7 @@ class TimelineViewModelTests: XCTestCase {
let deferred = deferFulfillment(viewModel.context.$viewState) { value in
value.pinnedEventIDs == ["test1", "test2"]
}
infoSubject.send(.init(roomInfo: RoomInfo(configuration)))
infoSubject.send(RoomInfoProxyMock(configuration))
try await deferred.fulfill()
}
@@ -497,7 +497,7 @@ class TimelineViewModelTests: XCTestCase {
let configuration = JoinedRoomProxyMockConfiguration(name: "",
powerLevelsConfiguration: .init(canUserPin: true))
let roomProxyMock = JoinedRoomProxyMock(configuration)
let infoSubject = CurrentValueSubject<RoomInfoProxy, Never>(.init(roomInfo: RoomInfo(configuration)))
let infoSubject = CurrentValueSubject<RoomInfoProxyProtocol, Never>(RoomInfoProxyMock(configuration))
roomProxyMock.underlyingInfoPublisher = infoSubject.asCurrentValuePublisher()
let viewModel = TimelineViewModel(roomProxy: roomProxyMock,
@@ -518,14 +518,17 @@ class TimelineViewModelTests: XCTestCase {
}
try await deferred.fulfill()
let powerLevelsMock = RoomPowerLevelsProxyMock(configuration: .init())
powerLevelsMock.canUserPinOrUnpinUserIDReturnValue = .success(false)
roomProxyMock.powerLevelsReturnValue = .success(powerLevelsMock)
let powerLevelsProxyMock = RoomPowerLevelsProxyMock(configuration: .init())
powerLevelsProxyMock.canUserPinOrUnpinUserIDReturnValue = .success(false)
roomProxyMock.powerLevelsReturnValue = .success(powerLevelsProxyMock)
let roomInfoProxyMock = RoomInfoProxyMock(configuration)
roomInfoProxyMock.powerLevels = powerLevelsProxyMock
deferred = deferFulfillment(viewModel.context.$viewState) { value in
!value.canCurrentUserPin
}
infoSubject.send(.init(roomInfo: RoomInfo(configuration)))
infoSubject.send(roomInfoProxyMock)
try await deferred.fulfill()
}