SDK update (#3891)

* Bump the RustSDK to v25.03.11

* Replace oidc login prompt with nil following the changes from https://github.com/matrix-org/matrix-rust-sdk/pull/4761

```
/// * `prompt` - The desired user experience in the web UI. No value means
///   that the user wishes to login into an existing account, and a value of
///   `Create` means that the user wishes to register a new account.
```

* Fix trailing closure warnings

* Update the client proxy after making `getNotificationSettings()` and  `cachedAvatarUrl()` async (they used to be blocking on the rust side).

* Move `Room.isEncrypted` to the info publisher and manually update the encryption state when creating the room.

* Bump the SDK again to v25.03.12 - This introduces a new way to configure the tokio runtime that we can use to have extensions use less memory
- introduce a new Target struct that takes care of setting up rust services (tracing and tokio) for our various targets
- cleanup MXLog and friends

* Address PR comments

* Bump the SDK again, switch back to using `.consent` as the OIDC login prompt (which was reintroduced in matrix-org/matrix-rust-sdk/pull/4791)
This commit is contained in:
Stefan Ceriu
2025-03-13 11:17:37 +02:00
committed by GitHub
parent 2b31ac6f88
commit 07e96115ce
34 changed files with 365 additions and 327 deletions
@@ -91,7 +91,8 @@ class AuthenticationService: AuthenticationServiceProtocol {
func urlForOIDCLogin() async -> Result<OIDCAuthorizationDataProxy, AuthenticationServiceError> {
guard let client else { return .failure(.oidcError(.urlFailure)) }
do {
let oidcData = try await client.urlForOidc(oidcConfiguration: appSettings.oidcConfiguration.rustValue, prompt: .consent)
let oidcData = try await client.urlForOidc(oidcConfiguration: appSettings.oidcConfiguration.rustValue,
prompt: .consent)
return .success(OIDCAuthorizationDataProxy(underlyingData: oidcData))
} catch {
MXLog.error("Failed to get URL for OIDC login: \(error)")
@@ -148,7 +148,7 @@ class ClientProxy: ClientProxyProtocol {
mediaLoader = MediaLoader(client: client)
notificationSettings = NotificationSettingsProxy(notificationSettings: client.getNotificationSettings())
notificationSettings = await NotificationSettingsProxy(notificationSettings: client.getNotificationSettings())
secureBackupController = SecureBackupController(encryption: client.encryption())
@@ -525,11 +525,11 @@ class ClientProxy: ClientProxyProtocol {
}
func roomSummaryForIdentifier(_ identifier: String) -> RoomSummary? {
staticRoomSummaryProvider.roomListPublisher.value.first(where: { $0.id == identifier })
staticRoomSummaryProvider.roomListPublisher.value.first { $0.id == identifier }
}
func roomSummaryForAlias(_ alias: String) -> RoomSummary? {
staticRoomSummaryProvider.roomListPublisher.value.first(where: { $0.canonicalAlias == alias || $0.alternativeAliases.contains(alias) })
staticRoomSummaryProvider.roomListPublisher.value.first { $0.canonicalAlias == alias || $0.alternativeAliases.contains(alias) }
}
func loadUserDisplayName() async -> Result<Void, ClientProxyError> {
@@ -806,16 +806,13 @@ class ClientProxy: ClientProxyProtocol {
private func loadUserAvatarURLFromCache() {
loadCachedAvatarURLTask = Task {
let urlString = await Task.dispatch(on: clientQueue) {
do {
return try self.client.cachedAvatarUrl()
} catch {
MXLog.error("Failed to look for the avatar url in the cache: \(error)")
return nil
}
do {
let urlString = try await self.client.cachedAvatarUrl()
guard !Task.isCancelled else { return }
self.userAvatarURLSubject.value = urlString.flatMap(URL.init)
} catch {
MXLog.error("Failed to look for the avatar url in the cache: \(error)")
}
guard !Task.isCancelled else { return }
self.userAvatarURLSubject.value = urlString.flatMap(URL.init)
}
}
@@ -70,7 +70,7 @@ class ElementCallWidgetDriver: WidgetCapabilitiesProvider, ElementCallWidgetDriv
return .failure(.roomInvalid)
}
let useEncryption = (try? room.isEncrypted()) ?? false
let useEncryption = await (try? room.latestEncryptionState() == .encrypted) ?? false
let widgetSettings: WidgetSettings
do {
@@ -100,10 +100,6 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
var ownUserID: String { room.ownUserId() }
var info: RoomInfoProxy { infoSubject.value }
var isEncrypted: Bool {
(try? room.isEncrypted()) ?? false
}
init(roomListService: RoomListServiceProtocol,
roomListItem: RoomListItemProtocol,
room: RoomProtocol) async throws {
@@ -116,6 +112,14 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
Task {
await updateMembers()
// Try to update the encryption state if it's unknown.
// This is an edge case as sliding sync should pass
// that information down to the room info on the rust side.
if room.encryptionState() == .unknown {
MXLog.error("The encryption state should almost always be known.")
_ = try? await room.latestEncryptionState()
}
}
}
@@ -142,7 +146,7 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
await subscribeToKnockRequests()
if isEncrypted { // This is actually blocking on the rust side and might make network requests
if infoPublisher.value.isEncrypted {
subscribeToIdentityStatusChanges()
}
}
@@ -42,6 +42,13 @@ struct RoomInfoProxy: BaseRoomInfoProxyProtocol {
return .room(id: id, name: displayName, avatarURL: avatarURL)
}
// Here we're assuming unknown rooms are unencrypted.
// Fortunately https://github.com/matrix-org/matrix-rust-sdk/pull/4778 makes that very much of an edge case and we
// also automatically start a `latestEncryptionState` fetch if needed.
// In the worst case, even if we are to assume a room is unencrypted, the SDK will still determine the correct
// state before any message is sent.
var isEncrypted: Bool { roomInfo.encryptionState == .encrypted }
var isDirect: Bool { roomInfo.isDirect }
var isPublic: Bool { roomInfo.isPublic }
var isSpace: Bool { roomInfo.isSpace }
@@ -63,8 +63,6 @@ enum KnockRequestsState {
// sourcery: AutoMockable
protocol JoinedRoomProxyProtocol: RoomProxyProtocol {
var isEncrypted: Bool { get }
var infoPublisher: CurrentValuePublisher<RoomInfoProxy, Never> { get }
var membersPublisher: CurrentValuePublisher<[RoomMemberProxyProtocol], Never> { get }
@@ -190,7 +188,7 @@ extension JoinedRoomProxyProtocol {
name: infoPublisher.value.displayName,
avatar: infoPublisher.value.avatar,
canonicalAlias: infoPublisher.value.canonicalAlias,
isEncrypted: isEncrypted,
isEncrypted: infoPublisher.value.isEncrypted,
isPublic: infoPublisher.value.isPublic,
isDirect: infoPublisher.value.isDirect)
}