Split module matrix to matrix.api with interfaces and data classes and matrix.impl with Rust implementation.

This commit is contained in:
Benoit Marty 2023-03-02 16:14:55 +01:00 committed by Benoit Marty
parent 6677f80abe
commit b8467e547c
56 changed files with 256 additions and 78 deletions

View file

@ -23,7 +23,7 @@ plugins {
}
android {
namespace = "io.element.android.libraries.matrix"
namespace = "io.element.android.libraries.matrix.api"
}
anvil {

View file

@ -16,7 +16,7 @@
package io.element.android.libraries.matrix.core
import io.element.android.libraries.matrix.BuildConfig
import io.element.android.libraries.matrix.api.BuildConfig
import timber.log.Timber
/**

View file

@ -46,5 +46,4 @@ interface MatrixRoom {
suspend fun replyMessage(eventId: EventId, message: String): Result<Unit>
suspend fun redactEvent(eventId: EventId, reason: String? = null): Result<Unit>
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 New Vector Ltd
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,6 +14,11 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix
package io.element.android.libraries.matrix.room
internal const val LOG_TAG = "Matrix"
import kotlinx.coroutines.flow.StateFlow
interface RoomSummaryDataSource {
fun roomSummaries(): StateFlow<List<RoomSummary>>
fun setSlidingSyncRange(range: IntRange)
}

View file

@ -18,7 +18,6 @@ package io.element.android.libraries.matrix.timeline
import io.element.android.libraries.matrix.core.EventId
import org.matrix.rustcomponents.sdk.EventTimelineItem
import org.matrix.rustcomponents.sdk.TimelineItem
import org.matrix.rustcomponents.sdk.VirtualTimelineItem
sealed interface MatrixTimelineItem {
@ -31,14 +30,3 @@ sealed interface MatrixTimelineItem {
object Other : MatrixTimelineItem
}
fun TimelineItem.asMatrixTimelineItem(): MatrixTimelineItem {
val asEvent = asEvent()
if (asEvent != null) {
return MatrixTimelineItem.Event(asEvent)
}
val asVirtual = asVirtual()
if (asVirtual != null) {
return MatrixTimelineItem.Virtual(asVirtual)
}
return MatrixTimelineItem.Other
}

View file

@ -74,12 +74,6 @@ sealed class LogLevel(val filter: String) {
object Error : LogLevel("error")
}
fun setupTracing(tracingConfiguration: TracingConfiguration) {
val filter = tracingConfiguration.filter
Timber.v("Tracing config filter = $filter")
org.matrix.rustcomponents.sdk.setupTracing(filter)
}
object TracingConfigurations {
val release = TracingConfiguration(overrides = mapOf(Target.Common to LogLevel.Info))
val debug = TracingConfiguration(overrides = mapOf(Target.Common to LogLevel.Info))

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("io.element.android-library")
alias(libs.plugins.anvil)
kotlin("plugin.serialization") version "1.8.10"
}
android {
namespace = "io.element.android.libraries.matrix.impl"
}
anvil {
generateDaggerFactories.set(true)
}
dependencies {
// api(projects.libraries.rustsdk)
api(libs.matrix.sdk)
implementation(projects.libraries.di)
implementation(projects.libraries.matrix.api)
implementation(libs.dagger)
implementation(projects.libraries.core)
implementation("net.java.dev.jna:jna:5.13.0@aar")
implementation(libs.androidx.datastore.preferences)
implementation(libs.serialization.json)
}

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2022 New Vector Ltd
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

View file

@ -14,18 +14,19 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix
package io.element.android.libraries.matrix.impl
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.matrix.MatrixClient
import io.element.android.libraries.matrix.core.RoomId
import io.element.android.libraries.matrix.core.UserId
import io.element.android.libraries.matrix.impl.media.RustMediaResolver
import io.element.android.libraries.matrix.impl.room.RustMatrixRoom
import io.element.android.libraries.matrix.impl.room.RustRoomSummaryDataSource
import io.element.android.libraries.matrix.impl.sync.SlidingSyncObserverProxy
import io.element.android.libraries.matrix.media.MediaResolver
import io.element.android.libraries.matrix.media.RustMediaResolver
import io.element.android.libraries.matrix.room.MatrixRoom
import io.element.android.libraries.matrix.room.RoomSummaryDataSource
import io.element.android.libraries.matrix.room.RustMatrixRoom
import io.element.android.libraries.matrix.room.RustRoomSummaryDataSource
import io.element.android.libraries.matrix.sync.SlidingSyncObserverProxy
import io.element.android.libraries.sessionstorage.SessionStore
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.withContext

View file

@ -14,18 +14,19 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.auth
package io.element.android.libraries.matrix.impl.auth
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.di.AppScope
import io.element.android.libraries.matrix.MatrixClient
import io.element.android.libraries.matrix.RustMatrixClient
import io.element.android.libraries.matrix.auth.MatrixAuthenticationService
import io.element.android.libraries.matrix.core.SessionId
import io.element.android.libraries.matrix.core.UserId
import io.element.android.libraries.matrix.impl.RustMatrixClient
import io.element.android.libraries.matrix.impl.util.logError
import io.element.android.libraries.matrix.session.SessionData
import io.element.android.libraries.sessionstorage.SessionStore
import io.element.android.libraries.matrix.util.logError
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.di
package io.element.android.libraries.matrix.impl.di
import com.squareup.anvil.annotations.ContributesTo
import dagger.Module

View file

@ -14,9 +14,10 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.media
package io.element.android.libraries.matrix.impl.media
import io.element.android.libraries.matrix.MatrixClient
import io.element.android.libraries.matrix.media.MediaResolver
import org.matrix.rustcomponents.sdk.mediaSourceFromUrl
internal class RustMediaResolver(private val client: MatrixClient) : MediaResolver {
@ -28,13 +29,14 @@ internal class RustMediaResolver(private val client: MatrixClient) : MediaResolv
}
override suspend fun resolve(meta: MediaResolver.Meta): ByteArray? {
if (meta.source == null) return null
return when (meta.kind) {
is MediaResolver.Kind.Content -> client.loadMediaContentForSource(meta.source)
val source = meta.source ?: return null
val kind = meta.kind
return when (kind) {
is MediaResolver.Kind.Content -> client.loadMediaContentForSource(source)
is MediaResolver.Kind.Thumbnail -> client.loadMediaThumbnailForSource(
meta.source,
meta.kind.width.toLong(),
meta.kind.height.toLong()
source,
kind.width.toLong(),
kind.height.toLong()
)
}.getOrNull()
}

View file

@ -14,10 +14,11 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.room
package io.element.android.libraries.matrix.impl.room
import io.element.android.libraries.matrix.impl.room.message.RoomMessageFactory
import io.element.android.libraries.matrix.core.RoomId
import io.element.android.libraries.matrix.room.message.RoomMessageFactory
import io.element.android.libraries.matrix.room.RoomSummaryDetails
import org.matrix.rustcomponents.sdk.Room
import org.matrix.rustcomponents.sdk.SlidingSyncRoom

View file

@ -14,13 +14,14 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.room
package io.element.android.libraries.matrix.impl.room
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.matrix.impl.timeline.RustMatrixTimeline
import io.element.android.libraries.matrix.core.EventId
import io.element.android.libraries.matrix.core.RoomId
import io.element.android.libraries.matrix.room.MatrixRoom
import io.element.android.libraries.matrix.timeline.MatrixTimeline
import io.element.android.libraries.matrix.timeline.RustMatrixTimeline
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
@ -32,7 +33,6 @@ import org.matrix.rustcomponents.sdk.SlidingSyncRoom
import org.matrix.rustcomponents.sdk.UpdateSummary
import org.matrix.rustcomponents.sdk.genTransactionId
import org.matrix.rustcomponents.sdk.messageEventContentFromMarkdown
import timber.log.Timber
class RustMatrixRoom(
private val slidingSyncUpdateFlow: Flow<UpdateSummary>,

View file

@ -14,11 +14,13 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.room
package io.element.android.libraries.matrix.impl.room
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.matrix.sync.roomListDiff
import io.element.android.libraries.matrix.sync.state
import io.element.android.libraries.matrix.impl.sync.roomListDiff
import io.element.android.libraries.matrix.impl.sync.state
import io.element.android.libraries.matrix.room.RoomSummary
import io.element.android.libraries.matrix.room.RoomSummaryDataSource
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
@ -39,11 +41,6 @@ import timber.log.Timber
import java.io.Closeable
import java.util.UUID
interface RoomSummaryDataSource {
fun roomSummaries(): StateFlow<List<RoomSummary>>
fun setSlidingSyncRange(range: IntRange)
}
internal class RustRoomSummaryDataSource(
private val slidingSyncUpdateFlow: Flow<UpdateSummary>,
private val slidingSync: SlidingSync,

View file

@ -14,10 +14,11 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.room.message
package io.element.android.libraries.matrix.impl.room.message
import io.element.android.libraries.matrix.core.EventId
import io.element.android.libraries.matrix.core.UserId
import io.element.android.libraries.matrix.room.message.RoomMessage
import org.matrix.rustcomponents.sdk.EventTimelineItem
class RoomMessageFactory {

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.sync
package io.element.android.libraries.matrix.impl.sync
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableSharedFlow

View file

@ -14,9 +14,9 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.sync
package io.element.android.libraries.matrix.impl.sync
import io.element.android.libraries.matrix.util.mxCallbackFlow
import io.element.android.libraries.matrix.impl.util.mxCallbackFlow
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch

View file

@ -14,8 +14,10 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.timeline
package io.element.android.libraries.matrix.impl.timeline
import io.element.android.libraries.matrix.timeline.MatrixTimeline
import io.element.android.libraries.matrix.timeline.MatrixTimelineItem
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.matrix.impl.timeline
import io.element.android.libraries.matrix.timeline.MatrixTimelineItem
import org.matrix.rustcomponents.sdk.TimelineItem
fun TimelineItem.asMatrixTimelineItem(): MatrixTimelineItem {
val asEvent = asEvent()
if (asEvent != null) {
return MatrixTimelineItem.Event(asEvent)
}
val asVirtual = asVirtual()
if (asVirtual != null) {
return MatrixTimelineItem.Virtual(asVirtual)
}
return MatrixTimelineItem.Other
}

View file

@ -14,12 +14,14 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.timeline
package io.element.android.libraries.matrix.impl.timeline
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.matrix.impl.util.TaskHandleBag
import io.element.android.libraries.matrix.core.EventId
import io.element.android.libraries.matrix.room.MatrixRoom
import io.element.android.libraries.matrix.util.TaskHandleBag
import io.element.android.libraries.matrix.timeline.MatrixTimeline
import io.element.android.libraries.matrix.timeline.MatrixTimelineItem
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.matrix.impl.tracing
import io.element.android.libraries.matrix.tracing.TracingConfiguration
import timber.log.Timber
fun setupTracing(tracingConfiguration: TracingConfiguration) {
val filter = tracingConfiguration.filter
Timber.v("Tracing config filter = $filter")
org.matrix.rustcomponents.sdk.setupTracing(filter)
}

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.util
package io.element.android.libraries.matrix.impl.util
import kotlinx.coroutines.channels.ProducerScope
import kotlinx.coroutines.channels.awaitClose

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.util
package io.element.android.libraries.matrix.impl.util
import org.matrix.rustcomponents.sdk.ClientException
import timber.log.Timber

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.util
package io.element.android.libraries.matrix.impl.util
import org.matrix.rustcomponents.sdk.TaskHandle
import java.util.concurrent.CopyOnWriteArraySet

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("io.element.android-library")
alias(libs.plugins.anvil)
kotlin("plugin.serialization") version "1.8.10"
}
android {
namespace = "io.element.android.libraries.matrix.test"
}
anvil {
generateDaggerFactories.set(true)
}
dependencies {
implementation(projects.libraries.di)
implementation(projects.libraries.matrix.api)
}

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2022 New Vector Ltd
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

View file

@ -25,6 +25,6 @@ android {
}
dependencies {
api(projects.libraries.matrix)
api(projects.libraries.matrix.api)
api(libs.coroutines.core)
}

View file

@ -35,7 +35,7 @@ dependencies {
anvil(projects.anvilcodegen)
implementation(projects.libraries.di)
implementation(projects.libraries.architecture)
implementation(projects.libraries.matrix)
implementation(projects.libraries.matrix.api)
implementation(projects.libraries.designsystem)
implementation(projects.libraries.core)
implementation(libs.coil.compose)

View file

@ -34,7 +34,7 @@ dependencies {
implementation(projects.libraries.uiStrings)
implementation(projects.libraries.androidutils)
implementation(projects.libraries.core)
implementation(projects.libraries.matrix)
implementation(projects.libraries.matrix.api)
implementation(projects.libraries.designsystem)
implementation(libs.wysiwyg)
implementation(libs.androidx.constraintlayout)