Update the SDK and handle API breaks. (#5871)

* Update the SDK and handle API breaks.

* Rename sdkUserThing to rustUserThing for consistency.

* Add user status ClientProxy methods.

* Rename UserStatus.UserSet to UserStatus.Raw.
This commit is contained in:
Doug
2026-07-14 16:35:37 +01:00
committed by GitHub
parent f776ea7133
commit 85f28d017d
17 changed files with 278 additions and 54 deletions
@@ -710,9 +710,7 @@ class ClientProxy: ClientProxyProtocol {
func setUserDisplayName(_ name: String) async -> Result<Void, ClientProxyError> {
do {
try await client.setDisplayName(name: name)
Task {
await self.loadUserProfile()
}
Task { await self.loadUserProfile() }
return .success(())
} catch {
MXLog.error("Failed setting user display name with error: \(error)")
@@ -729,9 +727,7 @@ class ClientProxy: ClientProxyProtocol {
do {
let data = try Data(contentsOf: imageURL)
try await client.uploadAvatar(mimeType: mimeType, data: data)
Task {
await self.loadUserProfile()
}
Task { await self.loadUserProfile() }
return .success(())
} catch {
MXLog.error("Failed setting user avatar with error: \(error)")
@@ -742,9 +738,7 @@ class ClientProxy: ClientProxyProtocol {
func removeUserAvatar() async -> Result<Void, ClientProxyError> {
do {
try await client.removeAvatar()
Task {
await self.loadUserProfile()
}
Task { await self.loadUserProfile() }
return .success(())
} catch {
MXLog.error("Failed removing user avatar with error: \(error)")
@@ -752,6 +746,28 @@ class ClientProxy: ClientProxyProtocol {
}
}
func setUserStatus(_ status: UserStatus.Raw) async -> Result<Void, ClientProxyError> {
do {
try await client.setUserStatus(status: status.rustValue)
Task { await self.loadUserProfile() }
return .success(())
} catch {
MXLog.error("Failed setting user status with error: \(error)")
return .failure(.sdkError(error))
}
}
func removeUserStatus() async -> Result<Void, ClientProxyError> {
do {
try await client.clearUserStatus()
Task { await self.loadUserProfile() }
return .success(())
} catch {
MXLog.error("Failed removing user status with error: \(error)")
return .failure(.sdkError(error))
}
}
func linkNewDeviceService() -> LinkNewDeviceServiceProtocol {
LinkNewDeviceService(handler: client.newGrantLoginWithQrCodeHandler())
}
@@ -786,7 +802,7 @@ class ClientProxy: ClientProxyProtocol {
func searchUsers(searchTerm: String, limit: UInt) async -> Result<SearchUsersResults, ClientProxyError> {
do {
return try await .success(.init(sdkResults: client.searchUsers(searchTerm: searchTerm, limit: UInt64(limit))))
return try await .success(.init(rustResults: client.searchUsers(searchTerm: searchTerm, limit: UInt64(limit))))
} catch {
MXLog.error("Failed searching users with error: \(error)")
return .failure(.sdkError(error))
@@ -795,7 +811,7 @@ class ClientProxy: ClientProxyProtocol {
func profile(for userID: String) async -> Result<UserProfile, ClientProxyError> {
do {
return try await .success(.init(sdkUserProfile: client.getProfile(userId: userID)))
return try await .success(.init(rustUserProfile: client.getProfile(userId: userID)))
} catch {
MXLog.error("Failed retrieving profile for userID: \(userID) with error: \(error)")
return .failure(.sdkError(error))
@@ -215,12 +215,11 @@ protocol ClientProxyProtocol: AnyObject {
func reportRoomForIdentifier(_ identifier: String, reason: String) async -> Result<Void, ClientProxyError>
@discardableResult func loadUserProfile() async -> Result<Void, ClientProxyError>
func setUserDisplayName(_ name: String) async -> Result<Void, ClientProxyError>
func setUserAvatar(media: MediaInfo) async -> Result<Void, ClientProxyError>
func removeUserAvatar() async -> Result<Void, ClientProxyError>
func setUserStatus(_ status: UserStatus.Raw) async -> Result<Void, ClientProxyError>
func removeUserStatus() async -> Result<Void, ClientProxyError>
func linkNewDeviceService() -> LinkNewDeviceServiceProtocol
@@ -190,7 +190,7 @@ class SessionVerificationControllerProxy: SessionVerificationControllerProxyProt
fileprivate func didReceiveVerificationRequest(details: MatrixRustSDK.SessionVerificationRequestDetails) {
MXLog.info("Received verification request \(details)")
let details = SessionVerificationRequestDetails(senderProfile: UserProfile(sdkUserProfile: details.senderProfile),
let details = SessionVerificationRequestDetails(senderProfile: UserProfile(rustUserProfile: details.senderProfile),
flowID: details.flowId,
deviceID: details.deviceId,
deviceDisplayName: details.deviceDisplayName,
@@ -291,7 +291,11 @@ private extension TimelineItemProxy {
threadRoot: nil,
threadSummary: nil))
let configuration = EventTimelineItemSDKMockConfiguration(sender: "@\(sender.lowercased()):matrix.org",
senderProfile: .ready(displayName: sender, displayNameAmbiguous: false, avatarUrl: nil),
senderProfile: .ready(displayName: sender,
displayNameAmbiguous: false,
avatarUrl: nil,
status: nil,
call: nil),
isOwn: isOwn,
canBeRepliedTo: true,
content: content)
@@ -19,7 +19,7 @@ nonisolated struct TimelineItemKeyForwarder: Identifiable, Hashable {
init(forwarderID: String, forwarderProfile: ProfileDetails) {
switch forwarderProfile {
case let .ready(displayName, _, _):
case let .ready(displayName, _, _, _, _):
self.init(id: forwarderID,
displayName: displayName)
default:
@@ -32,11 +32,12 @@ nonisolated struct TimelineItemSender: Identifiable, Hashable {
init(senderID: String, senderProfile: ProfileDetails) {
switch senderProfile {
case let .ready(displayName, isDisplayNameAmbiguous, avatarUrl):
case let .ready(displayName, isDisplayNameAmbiguous, avatarURL, status, call):
self.init(id: senderID,
displayName: displayName,
isDisplayNameAmbiguous: isDisplayNameAmbiguous,
avatarURL: avatarUrl.flatMap(URL.init(string:)))
avatarURL: avatarURL.flatMap(URL.init(string:)),
status: .init(rustStatus: status, rustCall: call))
default:
self.init(id: senderID,
displayName: nil,
@@ -71,7 +71,7 @@ nonisolated struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
isOutgoing: isOutgoing)
case .callInvite:
return buildCallInviteTimelineItem(for: eventItemProxy)
case .rtcNotification(let callIntent, let declinedBy):
case .rtcNotification(let callIntent, let declinedBy, _, _, _):
return buildCallNotificationTimelineItem(for: eventItemProxy, isDM: isDM, callIntent: callIntent, declinedBy: declinedBy)
}
}
@@ -36,18 +36,18 @@ nonisolated struct UserProfile: Hashable, Identifiable {
status = sender.status
}
init(sdkUserProfile: MatrixRustSDK.UserProfile) {
id = sdkUserProfile.userId
displayName = sdkUserProfile.displayName
avatarURL = sdkUserProfile.avatarUrl.flatMap(URL.init(string:))
status = .init()
init(rustUserProfile: MatrixRustSDK.UserProfile) {
id = rustUserProfile.userId
displayName = rustUserProfile.displayName
avatarURL = rustUserProfile.avatarUrl.flatMap(URL.init(string:))
status = .init(rustStatus: rustUserProfile.status, rustCall: rustUserProfile.call)
}
init(sdkRoomHero: MatrixRustSDK.RoomHero) {
id = sdkRoomHero.userId
displayName = sdkRoomHero.displayName
avatarURL = sdkRoomHero.avatarUrl.flatMap(URL.init(string:))
status = .init()
init(rustRoomHero: MatrixRustSDK.RoomHero) {
id = rustRoomHero.userId
displayName = rustRoomHero.displayName
avatarURL = rustRoomHero.avatarUrl.flatMap(URL.init(string:))
status = .init() // Requires https://github.com/matrix-org/matrix-rust-sdk/pull/6733
}
init(member: RoomMemberProxyProtocol) {
@@ -61,29 +61,36 @@ nonisolated struct UserProfile: Hashable, Identifiable {
}
}
// MARK: - Status
/// A user's status, created from a combination of their manually set status along with the call status indicator.
nonisolated struct UserStatus: Hashable {
/// The status manually set by the user (if any).
let userSet: UserSet?
/// The status automatically set by Element Call (while in a call).
/// The raw status that is manually set by the user (if any).
let raw: Raw?
/// The call status indicator automatically set by Element Call (while in a call).
let call: Call?
/// The status that should be displayed on the user's profile.
var displayed: DisplayedStatus? {
var displayed: Displayed? {
// The user-set status takes precedence over the call indicator.
userSet.map { .userSet($0) } ?? call.map { .inCall($0) }
raw.map { .userSet($0) } ?? call.map { .inCall($0) }
}
nonisolated struct UserSet: Hashable {
/// A status that is manually set by the user.
nonisolated struct Raw: Hashable {
let text: String
let emoji: Character
}
/// The call status indicator automatically set by Element Call.
nonisolated struct Call: Hashable {
let startDate: Date?
/// When the user joined the call, if known.
let joinedDate: Date?
}
nonisolated enum DisplayedStatus: Hashable {
case userSet(UserSet)
/// The status displayed in the UI.
nonisolated enum Displayed: Hashable {
case userSet(Raw)
case inCall(Call)
var text: String {
@@ -104,18 +111,47 @@ nonisolated struct UserStatus: Hashable {
nonisolated extension UserStatus {
init() {
self.init(userSet: nil, call: nil)
raw = nil
call = nil
}
init(rustStatus: MatrixRustSDK.UserStatus?, rustCall: MatrixRustSDK.UserCall?) {
raw = rustStatus.map(Raw.init)
call = rustCall.map(Call.init)
}
}
nonisolated extension UserStatus.Raw {
init(rustStatus: MatrixRustSDK.UserStatus) {
text = rustStatus.text
emoji = Character(rustStatus.emoji)
}
var rustValue: MatrixRustSDK.UserStatus {
.init(emoji: String(emoji), text: text)
}
}
nonisolated extension UserStatus.Call {
init(rustCall: MatrixRustSDK.UserCall) {
joinedDate = rustCall.callJoinedTs.map { Date(timeIntervalSince1970: Double($0)) }
}
var rustValue: MatrixRustSDK.UserCall {
.init(callJoinedTs: joinedDate.map { UInt64($0.timeIntervalSince1970) })
}
}
// MARK: - Search Results
struct SearchUsersResults {
let results: [UserProfile]
let limited: Bool
}
extension SearchUsersResults {
init(sdkResults: MatrixRustSDK.SearchUsersResults) {
results = sdkResults.results.map(UserProfile.init)
limited = sdkResults.limited
init(rustResults: MatrixRustSDK.SearchUsersResults) {
results = rustResults.results.map(UserProfile.init)
limited = rustResults.limited
}
}