mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Implement message sending. Refactor the timeline. Fix various UI/UX issues and add scroll to bottom timeline button.
This commit is contained in:
@@ -44,7 +44,7 @@ struct MediaProvider: MediaProviderProtocol {
|
||||
|
||||
processingQueue.async {
|
||||
do {
|
||||
let imageData = try client.loadImage(source: source.underlyingSource)
|
||||
let imageData = try client.getMediaContent(source: source.underlyingSource)
|
||||
|
||||
guard let image = UIImage(data: Data(bytes: imageData, count: imageData.count)) else {
|
||||
MXLog.error("Invalid image data")
|
||||
|
||||
@@ -46,4 +46,8 @@ struct MockRoomProxy: RoomProxyProtocol {
|
||||
func displayNameForUserId(_ userId: String, completion: @escaping (Result<String?, RoomProxyError>) -> Void) {
|
||||
|
||||
}
|
||||
|
||||
func sendMessage(_ message: String, callback: ((Result<Void, RoomProxyError>) -> Void)?) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,6 +165,25 @@ class RoomProxy: RoomProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func sendMessage(_ message: String, callback: ((Result<Void, RoomProxyError>) -> Void)?) {
|
||||
let messageContent = messageEventContentFromMarkdown(md: message)
|
||||
let transactionId = genTransactionId()
|
||||
|
||||
messageProcessingQueue.async {
|
||||
do {
|
||||
try self.room.send(msg: messageContent, txnId: transactionId)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
callback?(.success(()))
|
||||
}
|
||||
} catch {
|
||||
DispatchQueue.main.async {
|
||||
callback?(.failure(.failedSendingMessage))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
fileprivate func appendMessage(_ message: AnyMessage) {
|
||||
|
||||
@@ -14,6 +14,7 @@ enum RoomProxyError: Error {
|
||||
case backwardStreamNotAvailable
|
||||
case failedRetrievingMemberAvatarURL
|
||||
case failedRetrievingMemberDisplayName
|
||||
case failedSendingMessage
|
||||
}
|
||||
|
||||
enum RoomProxyCallback {
|
||||
@@ -43,5 +44,7 @@ protocol RoomProxyProtocol {
|
||||
|
||||
func paginateBackwards(count: UInt, callback: ((Result<Void, RoomProxyError>) -> Void)?)
|
||||
|
||||
func sendMessage(_ message: String, callback: ((Result<Void, RoomProxyError>) -> Void)?)
|
||||
|
||||
var callbacks: PassthroughSubject<RoomProxyCallback, Never> { get }
|
||||
}
|
||||
|
||||
@@ -30,4 +30,8 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
|
||||
func processItemDisappearance(_ itemId: String) {
|
||||
|
||||
}
|
||||
|
||||
func sendMessage(_ message: String) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,10 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
|
||||
}
|
||||
|
||||
func sendMessage(_ message: String) {
|
||||
timelineProvider.sendMessage(message)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@objc private func contentSizeCategoryDidChange() {
|
||||
|
||||
@@ -27,4 +27,6 @@ protocol RoomTimelineControllerProtocol {
|
||||
func processItemAppearance(_ itemId: String)
|
||||
|
||||
func processItemDisappearance(_ itemId: String)
|
||||
|
||||
func sendMessage(_ message: String)
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
|
||||
}.store(in: &cancellables)
|
||||
}
|
||||
|
||||
var messages: [RoomMessageProtocol] {
|
||||
roomProxy.messages
|
||||
}
|
||||
|
||||
func paginateBackwards(_ count: UInt, callback: ((Result<Void, RoomTimelineError>) -> Void)?) {
|
||||
self.roomProxy.paginateBackwards(count: count) { result in
|
||||
switch result {
|
||||
@@ -39,7 +43,14 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
var messages: [RoomMessageProtocol] {
|
||||
roomProxy.messages
|
||||
func sendMessage(_ message: String) {
|
||||
roomProxy.sendMessage(message) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
MXLog.error("Failed sending message with error: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,6 @@ protocol RoomTimelineProviderProtocol {
|
||||
var messages: [RoomMessageProtocol] { get }
|
||||
|
||||
func paginateBackwards(_ count: UInt, callback: ((Result<Void, RoomTimelineError>) -> Void)?)
|
||||
|
||||
func sendMessage(_ message: String)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user