Makes sendMessage suspend
This commit is contained in:
@@ -9,9 +9,7 @@ import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.matrix.rustcomponents.sdk.Room
|
||||
import org.matrix.rustcomponents.sdk.SlidingSyncRoom
|
||||
import org.matrix.rustcomponents.sdk.UpdateSummary
|
||||
import org.matrix.rustcomponents.sdk.*
|
||||
|
||||
class MatrixRoom(
|
||||
private val slidingSyncUpdateFlow: Flow<UpdateSummary>,
|
||||
@@ -69,4 +67,11 @@ class MatrixRoom(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun sendMessage(message: String): Result<Unit> = withContext(coroutineDispatchers.io) {
|
||||
val transactionId = genTransactionId()
|
||||
val content = messageEventContentFromMarkdown(message)
|
||||
runCatching {
|
||||
room.send(content, transactionId)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class MatrixTimeline(
|
||||
|
||||
private fun diffFlow(): Flow<Unit> {
|
||||
return room.timelineDiff()
|
||||
.chunk(100)
|
||||
.chunk(30)
|
||||
.onEach { timelineDiffs ->
|
||||
updateTimelineItems {
|
||||
timelineDiffs.onEach {
|
||||
@@ -119,10 +119,7 @@ class MatrixTimeline(
|
||||
* @param message markdown message
|
||||
*/
|
||||
suspend fun sendMessage(message: String): Result<Unit> {
|
||||
val transactionId = genTransactionId()
|
||||
val content = messageEventContentFromMarkdown(message)
|
||||
room.send(content, transactionId)
|
||||
return Result.success(Unit)
|
||||
return matrixRoom.sendMessage(message)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user