mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
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.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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+2
-5
@@ -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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user