Implement message sending. Refactor the timeline. Fix various UI/UX issues and add scroll to bottom timeline button.

This commit is contained in:
Stefan Ceriu
2022-04-18 10:54:48 +03:00
parent 2e92653c9d
commit 7f1c24059f
34 changed files with 802 additions and 262 deletions
@@ -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 }
}