Background execution (#100)

* #99 Implement background tasks

* #99 Add changelog

* #99 Fix some code smells

* #99 Use background tasks in room timeline controller

* #99 Move background task service into room proxy and media provider
This commit is contained in:
ismailgulek
2022-06-29 13:03:28 +03:00
committed by GitHub
parent d74158ced1
commit dbee1924eb
13 changed files with 619 additions and 9 deletions
+10 -1
View File
@@ -29,8 +29,10 @@ private class WeakRoomProxyWrapper: RoomDelegate {
class RoomProxy: RoomProxyProtocol {
private let room: Room
private let roomMessageFactory: RoomMessageFactoryProtocol
private let backgroundTaskService: BackgroundTaskServiceProtocol
private var backwardStream: BackwardsStreamProtocol?
private var sendMessageBgTask: BackgroundTaskProtocol?
private(set) var displayName: String?
@@ -38,9 +40,12 @@ class RoomProxy: RoomProxyProtocol {
private(set) var messages: [RoomMessageProtocol]
init(room: Room, roomMessageFactory: RoomMessageFactoryProtocol) {
init(room: Room,
roomMessageFactory: RoomMessageFactoryProtocol,
backgroundTaskService: BackgroundTaskServiceProtocol) {
self.room = room
self.roomMessageFactory = roomMessageFactory
self.backgroundTaskService = backgroundTaskService
messages = []
room.setDelegate(delegate: WeakRoomProxyWrapper(roomProxy: self))
@@ -157,6 +162,10 @@ class RoomProxy: RoomProxyProtocol {
}
func sendMessage(_ message: String) async -> Result<Void, RoomProxyError> {
sendMessageBgTask = backgroundTaskService.startBackgroundTask(withName: "SendMessage", isReusable: true)
defer {
sendMessageBgTask?.stop()
}
let messageContent = messageEventContentFromMarkdown(md: message)
let transactionId = genTransactionId()