Store and restore drafts (#2898)

This commit is contained in:
Mauro
2024-06-13 14:19:38 +02:00
committed by GitHub
parent b8dea8ac4e
commit cefa38049f
31 changed files with 1384 additions and 63 deletions
@@ -565,6 +565,37 @@ class RoomProxy: RoomProxyProtocol {
return .failure(.sdkError(error))
}
}
// MARK: - Drafts
func saveDraft(_ draft: ComposerDraft) async -> Result<Void, RoomProxyError> {
do {
try await room.saveComposerDraft(draft: draft)
return .success(())
} catch {
MXLog.error("Failed saving draft with error: \(error)")
return .failure(.sdkError(error))
}
}
func loadDraft() async -> Result<ComposerDraft?, RoomProxyError> {
do {
return try await .success(room.loadComposerDraft())
} catch {
MXLog.error("Failed restoring draft with error: \(error)")
return .failure(.sdkError(error))
}
}
func clearDraft() async -> Result<Void, RoomProxyError> {
do {
try await room.clearComposerDraft()
return .success(())
} catch {
MXLog.error("Failed clearing draft with error: \(error)")
return .failure(.sdkError(error))
}
}
// MARK: - Private
@@ -126,7 +126,6 @@ protocol RoomProxyProtocol {
// MARK: - Element Call
func canUserJoinCall(userID: String) async -> Result<Bool, RoomProxyError>
func elementCallWidgetDriver() -> ElementCallWidgetDriverProtocol
func sendCallNotificationIfNeeeded() async -> Result<Void, RoomProxyError>
@@ -134,8 +133,13 @@ protocol RoomProxyProtocol {
// MARK: - Permalinks
func matrixToPermalink() async -> Result<URL, RoomProxyError>
func matrixToEventPermalink(_ eventID: String) async -> Result<URL, RoomProxyError>
// MARK: - Drafts
func saveDraft(_ draft: ComposerDraft) async -> Result<Void, RoomProxyError>
func loadDraft() async -> Result<ComposerDraft?, RoomProxyError>
func clearDraft() async -> Result<Void, RoomProxyError>
}
extension RoomProxyProtocol {