Finish migration of Messages screen
This commit is contained in:
parent
ad3ac4cc3c
commit
ec1bbdeb9c
47 changed files with 354 additions and 315 deletions
|
|
@ -25,30 +25,23 @@ import io.element.android.x.matrix.core.SessionId
|
|||
import io.element.android.x.matrix.session.SessionStore
|
||||
import io.element.android.x.matrix.session.sessionId
|
||||
import io.element.android.x.matrix.util.logError
|
||||
import java.io.File
|
||||
import java.util.concurrent.Executors
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.matrix.rustcomponents.sdk.AuthenticationService
|
||||
import org.matrix.rustcomponents.sdk.Client
|
||||
import org.matrix.rustcomponents.sdk.ClientBuilder
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
@SingleIn(AppScope::class)
|
||||
class Matrix @Inject constructor(
|
||||
private val coroutineScope: CoroutineScope,
|
||||
private val coroutineDispatchers: CoroutineDispatchers,
|
||||
@ApplicationContext context: Context,
|
||||
) {
|
||||
private val coroutineDispatchers = CoroutineDispatchers(
|
||||
io = Dispatchers.IO,
|
||||
computation = Dispatchers.Default,
|
||||
main = Dispatchers.Main,
|
||||
diffUpdateDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
|
||||
)
|
||||
|
||||
private val baseDirectory = File(context.filesDir, "sessions")
|
||||
private val sessionStore = SessionStore(context)
|
||||
private val authService = AuthenticationService(baseDirectory.absolutePath)
|
||||
|
|
@ -57,7 +50,7 @@ class Matrix @Inject constructor(
|
|||
return sessionStore.isLoggedIn()
|
||||
}
|
||||
|
||||
suspend fun getLatestSessionId(): SessionId? = withContext(coroutineDispatchers.io){
|
||||
suspend fun getLatestSessionId(): SessionId? = withContext(coroutineDispatchers.io) {
|
||||
sessionStore.getLatestSession()?.sessionId()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package io.element.android.x.matrix.room
|
||||
|
||||
import io.element.android.x.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.x.matrix.core.EventId
|
||||
import io.element.android.x.matrix.core.RoomId
|
||||
import io.element.android.x.matrix.timeline.MatrixTimeline
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
|
@ -39,13 +40,15 @@ class MatrixRoom(
|
|||
private val coroutineDispatchers: CoroutineDispatchers,
|
||||
) {
|
||||
|
||||
fun syncUpdateFlow(): Flow<Unit> {
|
||||
fun syncUpdateFlow(): Flow<Long> {
|
||||
return slidingSyncUpdateFlow
|
||||
.filter {
|
||||
it.rooms.contains(room.id())
|
||||
}
|
||||
.map { }
|
||||
.onStart { emit(Unit) }
|
||||
.map {
|
||||
System.currentTimeMillis()
|
||||
}
|
||||
.onStart { emit(System.currentTimeMillis()) }
|
||||
}
|
||||
|
||||
fun timeline(): MatrixTimeline {
|
||||
|
|
@ -107,26 +110,26 @@ class MatrixRoom(
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun editMessage(originalEventId: String, message: String): Result<Unit> = withContext(coroutineDispatchers.io) {
|
||||
suspend fun editMessage(originalEventId: EventId, message: String): Result<Unit> = withContext(coroutineDispatchers.io) {
|
||||
val transactionId = genTransactionId()
|
||||
// val content = messageEventContentFromMarkdown(message)
|
||||
runCatching {
|
||||
room.edit(/* TODO use content */ message, originalEventId, transactionId)
|
||||
room.edit(/* TODO use content */ message, originalEventId.value, transactionId)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun replyMessage(eventId: String, message: String): Result<Unit> = withContext(coroutineDispatchers.io) {
|
||||
suspend fun replyMessage(eventId: EventId, message: String): Result<Unit> = withContext(coroutineDispatchers.io) {
|
||||
val transactionId = genTransactionId()
|
||||
// val content = messageEventContentFromMarkdown(message)
|
||||
runCatching {
|
||||
room.sendReply(/* TODO use content */ message, eventId, transactionId)
|
||||
room.sendReply(/* TODO use content */ message, eventId.value, transactionId)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun redactEvent(eventId: String, reason: String? = null) = withContext(coroutineDispatchers.io) {
|
||||
suspend fun redactEvent(eventId: EventId, reason: String? = null) = withContext(coroutineDispatchers.io) {
|
||||
val transactionId = genTransactionId()
|
||||
runCatching {
|
||||
room.redact(eventId, reason, transactionId)
|
||||
room.redact(eventId.value, reason, transactionId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package io.element.android.x.matrix.timeline
|
||||
|
||||
import io.element.android.x.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.x.matrix.core.EventId
|
||||
import io.element.android.x.matrix.room.MatrixRoom
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
|
|
@ -146,11 +147,11 @@ class MatrixTimeline(
|
|||
return matrixRoom.sendMessage(message)
|
||||
}
|
||||
|
||||
suspend fun editMessage(originalEventId: String, message: String): Result<Unit> {
|
||||
suspend fun editMessage(originalEventId: EventId, message: String): Result<Unit> {
|
||||
return matrixRoom.editMessage(originalEventId, message = message)
|
||||
}
|
||||
|
||||
suspend fun replyMessage(inReplyToEventId: String, message: String): Result<Unit> {
|
||||
suspend fun replyMessage(inReplyToEventId: EventId, message: String): Result<Unit> {
|
||||
return matrixRoom.replyMessage(inReplyToEventId, message)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue