Makes sendMessage suspend
This commit is contained in:
parent
6e20c4455f
commit
1fcf63abe5
2 changed files with 10 additions and 8 deletions
|
|
@ -9,9 +9,7 @@ import kotlinx.coroutines.flow.filter
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.matrix.rustcomponents.sdk.Room
|
import org.matrix.rustcomponents.sdk.*
|
||||||
import org.matrix.rustcomponents.sdk.SlidingSyncRoom
|
|
||||||
import org.matrix.rustcomponents.sdk.UpdateSummary
|
|
||||||
|
|
||||||
class MatrixRoom(
|
class MatrixRoom(
|
||||||
private val slidingSyncUpdateFlow: Flow<UpdateSummary>,
|
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> {
|
private fun diffFlow(): Flow<Unit> {
|
||||||
return room.timelineDiff()
|
return room.timelineDiff()
|
||||||
.chunk(100)
|
.chunk(30)
|
||||||
.onEach { timelineDiffs ->
|
.onEach { timelineDiffs ->
|
||||||
updateTimelineItems {
|
updateTimelineItems {
|
||||||
timelineDiffs.onEach {
|
timelineDiffs.onEach {
|
||||||
|
|
@ -119,10 +119,7 @@ class MatrixTimeline(
|
||||||
* @param message markdown message
|
* @param message markdown message
|
||||||
*/
|
*/
|
||||||
suspend fun sendMessage(message: String): Result<Unit> {
|
suspend fun sendMessage(message: String): Result<Unit> {
|
||||||
val transactionId = genTransactionId()
|
return matrixRoom.sendMessage(message)
|
||||||
val content = messageEventContentFromMarkdown(message)
|
|
||||||
room.send(content, transactionId)
|
|
||||||
return Result.success(Unit)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue