Fixes vector-im/element-x-ios/issues/114 - Replying to timeline items

This commit is contained in:
Stefan Ceriu
2022-09-14 16:21:23 +03:00
committed by GitHub
parent dd2385711a
commit ffee192e89
18 changed files with 229 additions and 79 deletions
@@ -54,7 +54,7 @@ struct MockRoomProxy: RoomProxyProtocol {
.failure(.backwardStreamNotAvailable)
}
func sendMessage(_ message: String) async -> Result<Void, RoomProxyError> {
func sendMessage(_ message: String, inReplyToEventId: String? = nil) async -> Result<Void, RoomProxyError> {
.failure(.failedSendingMessage)
}
@@ -175,17 +175,24 @@ class RoomProxy: RoomProxyProtocol {
.value
}
func sendMessage(_ message: String) async -> Result<Void, RoomProxyError> {
func sendMessage(_ message: String, inReplyToEventId: String? = nil) async -> Result<Void, RoomProxyError> {
sendMessageBgTask = backgroundTaskService.startBackgroundTask(withName: "SendMessage", isReusable: true)
defer {
sendMessageBgTask?.stop()
}
let messageContent = messageEventContentFromMarkdown(md: message)
let transactionId = genTransactionId()
return await Task(priority: .high) { () -> Result<Void, RoomProxyError> in
do {
// Disabled until available in Rust
// if let inReplyToEventId = inReplyToEventId {
// #warning("Markdown support when available in Ruma")
// try self.room.sendReply(msg: message, inReplyToEventId: inReplyToEventId, txnId: transactionId)
// } else {
let messageContent = messageEventContentFromMarkdown(md: message)
try self.room.send(msg: messageContent, txnId: transactionId)
// }
return .success(())
} catch {
return .failure(.failedSendingMessage)
@@ -55,9 +55,15 @@ protocol RoomProxyProtocol {
func paginateBackwards(count: UInt) async -> Result<Void, RoomProxyError>
func sendMessage(_ message: String) async -> Result<Void, RoomProxyError>
func sendMessage(_ message: String, inReplyToEventId: String?) async -> Result<Void, RoomProxyError>
func redact(_ eventID: String) async -> Result<Void, RoomProxyError>
var callbacks: PassthroughSubject<RoomProxyCallback, Never> { get }
}
extension RoomProxyProtocol {
func sendMessage(_ message: String) async -> Result<Void, RoomProxyError> {
await sendMessage(message, inReplyToEventId: nil)
}
}
@@ -66,5 +66,7 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
func sendMessage(_ message: String) async { }
func sendReply(_ message: String, to itemId: String) async { }
func redact(_ eventID: String) async { }
}
@@ -104,13 +104,20 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
}
}
func sendReply(_ message: String, to itemId: String) async {
switch await timelineProvider.sendMessage(message, inReplyToItemId: itemId) {
default:
break
}
}
func redact(_ eventID: String) async {
switch await timelineProvider.redact(eventID) {
default:
break
}
}
// MARK: - Private
@objc private func contentSizeCategoryDidChange() {
@@ -41,5 +41,7 @@ protocol RoomTimelineControllerProtocol {
func sendMessage(_ message: String) async
func sendReply(_ message: String, to itemId: String) async
func redact(_ eventID: String) async
}
@@ -51,8 +51,8 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
}
}
func sendMessage(_ message: String) async -> Result<Void, RoomTimelineProviderError> {
switch await roomProxy.sendMessage(message) {
func sendMessage(_ message: String, inReplyToItemId: String?) async -> Result<Void, RoomTimelineProviderError> {
switch await roomProxy.sendMessage(message, inReplyToEventId: inReplyToItemId) {
case .success:
return .success(())
case .failure:
@@ -35,7 +35,13 @@ protocol RoomTimelineProviderProtocol {
func paginateBackwards(_ count: UInt) async -> Result<Void, RoomTimelineProviderError>
func sendMessage(_ message: String) async -> Result<Void, RoomTimelineProviderError>
func sendMessage(_ message: String, inReplyToItemId: String?) async -> Result<Void, RoomTimelineProviderError>
func redact(_ eventID: String) async -> Result<Void, RoomTimelineProviderError>
}
extension RoomTimelineProviderProtocol {
func sendMessage(_ message: String) async -> Result<Void, RoomTimelineProviderError> {
await sendMessage(message, inReplyToItemId: nil)
}
}