mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
Use RustSDK permalink builders:
- replace event permalinks on the room screen interaction handler - replace the one use don the room details screen - deprecate previous AttributedStringBuilder methods - there's more work required on the AttributedStringBuilder mentions handler before we can completely drop the iOS implementations
This commit is contained in:
@@ -3146,6 +3146,44 @@ class RoomProxyMock: RoomProxyProtocol {
|
|||||||
return elementCallWidgetDriverReturnValue
|
return elementCallWidgetDriverReturnValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//MARK: - matrixToPermalink
|
||||||
|
|
||||||
|
var matrixToPermalinkCallsCount = 0
|
||||||
|
var matrixToPermalinkCalled: Bool {
|
||||||
|
return matrixToPermalinkCallsCount > 0
|
||||||
|
}
|
||||||
|
var matrixToPermalinkReturnValue: Result<URL, RoomProxyError>!
|
||||||
|
var matrixToPermalinkClosure: (() async -> Result<URL, RoomProxyError>)?
|
||||||
|
|
||||||
|
func matrixToPermalink() async -> Result<URL, RoomProxyError> {
|
||||||
|
matrixToPermalinkCallsCount += 1
|
||||||
|
if let matrixToPermalinkClosure = matrixToPermalinkClosure {
|
||||||
|
return await matrixToPermalinkClosure()
|
||||||
|
} else {
|
||||||
|
return matrixToPermalinkReturnValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//MARK: - matrixToEventPermalink
|
||||||
|
|
||||||
|
var matrixToEventPermalinkCallsCount = 0
|
||||||
|
var matrixToEventPermalinkCalled: Bool {
|
||||||
|
return matrixToEventPermalinkCallsCount > 0
|
||||||
|
}
|
||||||
|
var matrixToEventPermalinkReceivedEventID: String?
|
||||||
|
var matrixToEventPermalinkReceivedInvocations: [String] = []
|
||||||
|
var matrixToEventPermalinkReturnValue: Result<URL, RoomProxyError>!
|
||||||
|
var matrixToEventPermalinkClosure: ((String) async -> Result<URL, RoomProxyError>)?
|
||||||
|
|
||||||
|
func matrixToEventPermalink(_ eventID: String) async -> Result<URL, RoomProxyError> {
|
||||||
|
matrixToEventPermalinkCallsCount += 1
|
||||||
|
matrixToEventPermalinkReceivedEventID = eventID
|
||||||
|
matrixToEventPermalinkReceivedInvocations.append(eventID)
|
||||||
|
if let matrixToEventPermalinkClosure = matrixToEventPermalinkClosure {
|
||||||
|
return await matrixToEventPermalinkClosure(eventID)
|
||||||
|
} else {
|
||||||
|
return matrixToEventPermalinkReturnValue
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class RoomSummaryProviderMock: RoomSummaryProviderProtocol {
|
class RoomSummaryProviderMock: RoomSummaryProviderProtocol {
|
||||||
var roomListPublisher: CurrentValuePublisher<[RoomSummary], Never> {
|
var roomListPublisher: CurrentValuePublisher<[RoomSummary], Never> {
|
||||||
|
|||||||
@@ -132,5 +132,8 @@ extension RoomProxyMock {
|
|||||||
widgetDriver.startBaseURLClientIDReturnValue = .success(url)
|
widgetDriver.startBaseURLClientIDReturnValue = .success(url)
|
||||||
|
|
||||||
elementCallWidgetDriverReturnValue = widgetDriver
|
elementCallWidgetDriverReturnValue = widgetDriver
|
||||||
|
|
||||||
|
matrixToPermalinkReturnValue = .success(.homeDirectory)
|
||||||
|
matrixToEventPermalinkReturnValue = .success(.homeDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ enum PermalinkBuilder {
|
|||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated, message: "Use a room's `matrixToPermalink` method instead")
|
||||||
static func permalinkTo(roomIdentifier: String, baseURL: URL) throws -> URL {
|
static func permalinkTo(roomIdentifier: String, baseURL: URL) throws -> URL {
|
||||||
guard MatrixEntityRegex.isMatrixRoomIdentifier(roomIdentifier) else {
|
guard MatrixEntityRegex.isMatrixRoomIdentifier(roomIdentifier) else {
|
||||||
throw PermalinkBuilderError.invalidRoomIdentifier
|
throw PermalinkBuilderError.invalidRoomIdentifier
|
||||||
@@ -100,6 +101,7 @@ enum PermalinkBuilder {
|
|||||||
return try permalinkTo(roomIdentifierOrAlias: roomIdentifier, baseURL: baseURL)
|
return try permalinkTo(roomIdentifierOrAlias: roomIdentifier, baseURL: baseURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated, message: "Use a room's `matrixToPermalink` method instead")
|
||||||
static func permalinkTo(roomAlias: String, baseURL: URL) throws -> URL {
|
static func permalinkTo(roomAlias: String, baseURL: URL) throws -> URL {
|
||||||
guard MatrixEntityRegex.isMatrixRoomAlias(roomAlias) else {
|
guard MatrixEntityRegex.isMatrixRoomAlias(roomAlias) else {
|
||||||
throw PermalinkBuilderError.invalidRoomAlias
|
throw PermalinkBuilderError.invalidRoomAlias
|
||||||
@@ -108,6 +110,7 @@ enum PermalinkBuilder {
|
|||||||
return try permalinkTo(roomIdentifierOrAlias: roomAlias, baseURL: baseURL)
|
return try permalinkTo(roomIdentifierOrAlias: roomAlias, baseURL: baseURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated, message: "Use a room's `matrixToEventPermalink` method instead")
|
||||||
static func permalinkTo(eventIdentifier: String, roomIdentifier: String, baseURL: URL) throws -> URL {
|
static func permalinkTo(eventIdentifier: String, roomIdentifier: String, baseURL: URL) throws -> URL {
|
||||||
guard MatrixEntityRegex.isMatrixEventIdentifier(eventIdentifier) else {
|
guard MatrixEntityRegex.isMatrixEventIdentifier(eventIdentifier) else {
|
||||||
throw PermalinkBuilderError.invalidEventIdentifier
|
throw PermalinkBuilderError.invalidEventIdentifier
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ struct RoomDetailsScreenViewState: BindableState {
|
|||||||
|
|
||||||
let isEncrypted: Bool
|
let isEncrypted: Bool
|
||||||
let isDirect: Bool
|
let isDirect: Bool
|
||||||
let permalink: URL?
|
var permalink: URL?
|
||||||
|
|
||||||
var topic: AttributedString?
|
var topic: AttributedString?
|
||||||
var topicSummary: AttributedString?
|
var topicSummary: AttributedString?
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
|||||||
super.init(initialViewState: .init(details: roomProxy.details,
|
super.init(initialViewState: .init(details: roomProxy.details,
|
||||||
isEncrypted: roomProxy.isEncrypted,
|
isEncrypted: roomProxy.isEncrypted,
|
||||||
isDirect: roomProxy.isDirect,
|
isDirect: roomProxy.isDirect,
|
||||||
permalink: roomProxy.permalink,
|
|
||||||
topic: topic,
|
topic: topic,
|
||||||
topicSummary: topic?.unattributedStringByReplacingNewlinesWithSpaces(),
|
topicSummary: topic?.unattributedStringByReplacingNewlinesWithSpaces(),
|
||||||
joinedMembersCount: roomProxy.joinedMembersCount,
|
joinedMembersCount: roomProxy.joinedMembersCount,
|
||||||
@@ -67,6 +66,12 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
|||||||
bindings: .init()),
|
bindings: .init()),
|
||||||
imageProvider: mediaProvider)
|
imageProvider: mediaProvider)
|
||||||
|
|
||||||
|
Task {
|
||||||
|
if case let .success(permalinkURL) = await roomProxy.matrixToPermalink() {
|
||||||
|
state.permalink = permalinkURL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateRoomInfo()
|
updateRoomInfo()
|
||||||
Task { await updatePowerLevelPermissions() }
|
Task { await updatePowerLevelPermissions() }
|
||||||
|
|
||||||
|
|||||||
@@ -208,17 +208,18 @@ class RoomScreenInteractionHandler {
|
|||||||
MXLog.error("Cannot edit item with id: \(timelineItem.id)")
|
MXLog.error("Cannot edit item with id: \(timelineItem.id)")
|
||||||
}
|
}
|
||||||
case .copyPermalink:
|
case .copyPermalink:
|
||||||
do {
|
guard let eventID = eventTimelineItem.id.eventID else {
|
||||||
guard let eventID = eventTimelineItem.id.eventID else {
|
actionsSubject.send(.displayError(.alert(L10n.errorFailedCreatingThePermalink)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Task {
|
||||||
|
guard case let .success(permalinkURL) = await roomProxy.matrixToEventPermalink(eventID) else {
|
||||||
actionsSubject.send(.displayError(.alert(L10n.errorFailedCreatingThePermalink)))
|
actionsSubject.send(.displayError(.alert(L10n.errorFailedCreatingThePermalink)))
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let permalink = try PermalinkBuilder.permalinkTo(eventIdentifier: eventID, roomIdentifier: timelineController.roomID,
|
UIPasteboard.general.url = permalinkURL
|
||||||
baseURL: appSettings.permalinkBaseURL)
|
|
||||||
UIPasteboard.general.url = permalink
|
|
||||||
} catch {
|
|
||||||
actionsSubject.send(.displayError(.alert(L10n.errorFailedCreatingThePermalink)))
|
|
||||||
}
|
}
|
||||||
case .redact:
|
case .redact:
|
||||||
Task {
|
Task {
|
||||||
|
|||||||
@@ -529,6 +529,40 @@ class RoomProxy: RoomProxyProtocol {
|
|||||||
ElementCallWidgetDriver(room: room)
|
ElementCallWidgetDriver(room: room)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Permalinks
|
||||||
|
|
||||||
|
func matrixToPermalink() async -> Result<URL, RoomProxyError> {
|
||||||
|
do {
|
||||||
|
let urlString = try await room.matrixToPermalink()
|
||||||
|
|
||||||
|
guard let url = URL(string: urlString) else {
|
||||||
|
MXLog.error("Invalid permalink URL string: \(urlString)")
|
||||||
|
return .failure(.generic("Invalid permalink URL string: \(urlString)"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return .success(url)
|
||||||
|
} catch {
|
||||||
|
MXLog.error("Failed creating permalink for roomID: \(id) with error: \(error)")
|
||||||
|
return .failure(.generic(error.localizedDescription))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func matrixToEventPermalink(_ eventID: String) async -> Result<URL, RoomProxyError> {
|
||||||
|
do {
|
||||||
|
let urlString = try await room.matrixToEventPermalink(eventId: eventID)
|
||||||
|
|
||||||
|
guard let url = URL(string: urlString) else {
|
||||||
|
MXLog.error("Invalid permalink URL string: \(urlString)")
|
||||||
|
return .failure(.generic("Invalid permalink URL string: \(urlString)"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return .success(url)
|
||||||
|
} catch {
|
||||||
|
MXLog.error("Failed creating permalink for eventID: \(eventID) with error: \(error)")
|
||||||
|
return .failure(.generic(error.localizedDescription))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|
||||||
private func subscribeToRoomInfoUpdates() {
|
private func subscribeToRoomInfoUpdates() {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import Foundation
|
|||||||
import MatrixRustSDK
|
import MatrixRustSDK
|
||||||
|
|
||||||
enum RoomProxyError: Error, Equatable {
|
enum RoomProxyError: Error, Equatable {
|
||||||
|
case generic(String?)
|
||||||
case failedRedactingEvent
|
case failedRedactingEvent
|
||||||
case failedReportingContent
|
case failedReportingContent
|
||||||
case failedRetrievingMember
|
case failedRetrievingMember
|
||||||
@@ -139,6 +140,12 @@ protocol RoomProxyProtocol {
|
|||||||
func canUserJoinCall(userID: String) async -> Result<Bool, RoomProxyError>
|
func canUserJoinCall(userID: String) async -> Result<Bool, RoomProxyError>
|
||||||
|
|
||||||
func elementCallWidgetDriver() -> ElementCallWidgetDriverProtocol
|
func elementCallWidgetDriver() -> ElementCallWidgetDriverProtocol
|
||||||
|
|
||||||
|
// MARK: - Permalinks
|
||||||
|
|
||||||
|
func matrixToPermalink() async -> Result<URL, RoomProxyError>
|
||||||
|
|
||||||
|
func matrixToEventPermalink(_ eventID: String) async -> Result<URL, RoomProxyError>
|
||||||
}
|
}
|
||||||
|
|
||||||
extension RoomProxyProtocol {
|
extension RoomProxyProtocol {
|
||||||
@@ -149,19 +156,6 @@ extension RoomProxyProtocol {
|
|||||||
canonicalAlias: canonicalAlias)
|
canonicalAlias: canonicalAlias)
|
||||||
}
|
}
|
||||||
|
|
||||||
var permalink: URL? {
|
|
||||||
if let canonicalAlias, let link = try? PermalinkBuilder.permalinkTo(roomAlias: canonicalAlias,
|
|
||||||
baseURL: ServiceLocator.shared.settings.permalinkBaseURL) {
|
|
||||||
return link
|
|
||||||
} else if let link = try? PermalinkBuilder.permalinkTo(roomIdentifier: id,
|
|
||||||
baseURL: ServiceLocator.shared.settings.permalinkBaseURL) {
|
|
||||||
return link
|
|
||||||
} else {
|
|
||||||
MXLog.error("Failed to build permalink for Room: \(id)")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Avoids to duplicate the same logic around in the app
|
// Avoids to duplicate the same logic around in the app
|
||||||
// Probably this should be done in rust.
|
// Probably this should be done in rust.
|
||||||
var roomTitle: String {
|
var roomTitle: String {
|
||||||
|
|||||||
Reference in New Issue
Block a user