Finish migration of Messages screen

This commit is contained in:
ganfra 2023-01-13 18:05:14 +01:00
parent ad3ac4cc3c
commit ec1bbdeb9c
47 changed files with 354 additions and 315 deletions

View file

@ -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()
}

View file

@ -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)
}
}
}

View file

@ -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)
}

View file

@ -26,8 +26,9 @@ import io.element.android.x.matrix.ui.model.MatrixUser
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.asFlow
import javax.inject.Inject
class MatrixItemHelper(
class MatrixItemHelper @Inject constructor(
private val client: MatrixClient
) {
/**

View file

@ -32,6 +32,7 @@ android {
dependencies {
implementation(project(":libraries:elementresources"))
implementation(project(":libraries:core"))
implementation(project(":libraries:matrix"))
implementation(libs.wysiwyg)
implementation(libs.androidx.constraintlayout)
implementation("com.google.android.material:material:1.7.0")

View file

@ -17,31 +17,32 @@
package io.element.android.x.textcomposer
import android.os.Parcelable
import io.element.android.x.matrix.core.EventId
import kotlinx.parcelize.Parcelize
sealed interface MessageComposerMode : Parcelable {
@Parcelize
data class Normal(val content: CharSequence?) : MessageComposerMode
sealed class Special(open val eventId: String, open val defaultContent: CharSequence) :
sealed class Special(open val eventId: EventId, open val defaultContent: CharSequence) :
MessageComposerMode
@Parcelize
data class Edit(override val eventId: String, override val defaultContent: CharSequence) :
data class Edit(override val eventId: EventId, override val defaultContent: CharSequence) :
Special(eventId, defaultContent)
@Parcelize
class Quote(override val eventId: String, override val defaultContent: CharSequence) :
class Quote(override val eventId: EventId, override val defaultContent: CharSequence) :
Special(eventId, defaultContent)
@Parcelize
class Reply(
val senderName: String,
override val eventId: String,
override val eventId: EventId,
override val defaultContent: CharSequence
) : Special(eventId, defaultContent)
val relatedEventId: String?
val relatedEventId: EventId?
get() = when (this) {
is Normal -> null
is Edit -> eventId