Skip to content

Commit a6fedba

Browse files
Update dependency org.matrix.rustcomponents:sdk-android to v0.2.60 (#3827)
* Update dependency org.matrix.rustcomponents:sdk-android to v0.2.60 * Fix SDK API breaks: - Map new `QueueWedgeError` cases. - Add `MediaUploadOnSendQueue` feature flag enabled on debug and nightly builds: this will by used by `Timeline.send*` media functions fot its new `useSendQueue` parameter. --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Jorge Martín <[email protected]>
1 parent 2386350 commit a6fedba

File tree

10 files changed

+61
-16
lines changed

10 files changed

+61
-16
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ jsoup = "org.jsoup:jsoup:1.18.1"
173173
appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" }
174174
molecule-runtime = "app.cash.molecule:molecule-runtime:2.0.0"
175175
timber = "com.jakewharton.timber:timber:5.0.1"
176-
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.2.59"
176+
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.2.60"
177177
matrix_richtexteditor = { module = "io.element.android:wysiwyg", version.ref = "wysiwyg" }
178178
matrix_richtexteditor_compose = { module = "io.element.android:wysiwyg-compose", version.ref = "wysiwyg" }
179179
sqldelight-driver-android = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" }

libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package io.element.android.libraries.featureflag.api
99

1010
import io.element.android.appconfig.OnBoardingConfig
1111
import io.element.android.libraries.core.meta.BuildMeta
12+
import io.element.android.libraries.core.meta.BuildType
1213

1314
/**
1415
* To enable or disable a FeatureFlags, change the `defaultValue` value.
@@ -132,4 +133,11 @@ enum class FeatureFlags(
132133
defaultValue = { false },
133134
isFinished = false,
134135
),
136+
MediaUploadOnSendQueue(
137+
key = "feature.media_upload_through_send_queue",
138+
title = "Media upload through send queue",
139+
description = "Experimental support for treating media uploads as regular events, with an improved retry and cancellation implementation.",
140+
defaultValue = { buildMeta -> buildMeta.buildType != BuildType.RELEASE },
141+
isFinished = false,
142+
),
135143
}

libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/timeline/item/event/LocalEventSendState.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ sealed interface LocalEventSendState {
3434
*/
3535
val users: List<UserId>
3636
) : VerifiedUser
37+
38+
data class InvalidMimeType(val mimeType: String) : Failed
39+
40+
data object MissingMediaContent : Failed
3741
}
3842

3943
data class Sent(

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import io.element.android.libraries.androidutils.file.safeDelete
1212
import io.element.android.libraries.core.bool.orFalse
1313
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
1414
import io.element.android.libraries.core.coroutine.childScope
15+
import io.element.android.libraries.featureflag.api.FeatureFlagService
1516
import io.element.android.libraries.matrix.api.MatrixClient
1617
import io.element.android.libraries.matrix.api.core.DeviceId
1718
import io.element.android.libraries.matrix.api.core.ProgressCallback
@@ -125,6 +126,7 @@ class RustMatrixClient(
125126
baseCacheDirectory: File,
126127
clock: SystemClock,
127128
timelineEventTypeFilterFactory: TimelineEventTypeFilterFactory,
129+
featureFlagService: FeatureFlagService,
128130
) : MatrixClient {
129131
override val sessionId: UserId = UserId(client.userId())
130132
override val deviceId: DeviceId = DeviceId(client.deviceId())
@@ -188,6 +190,7 @@ class RustMatrixClient(
188190
roomContentForwarder = RoomContentForwarder(innerRoomListService),
189191
roomSyncSubscriber = roomSyncSubscriber,
190192
timelineEventTypeFilterFactory = timelineEventTypeFilterFactory,
193+
featureFlagService = featureFlagService,
191194
)
192195

193196
override val mediaLoader: MatrixMediaLoader = RustMediaLoader(

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClientFactory.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class RustMatrixClientFactory @Inject constructor(
8282
baseCacheDirectory = cacheDirectory,
8383
clock = clock,
8484
timelineEventTypeFilterFactory = timelineEventTypeFilterFactory,
85+
featureFlagService = featureFlagService,
8586
).also {
8687
Timber.tag(it.toString()).d("Creating Client with access token '$anonymizedAccessToken' and refresh token '$anonymizedRefreshToken'")
8788
}

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package io.element.android.libraries.matrix.impl.room
1010
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
1111
import io.element.android.libraries.core.coroutine.childScope
1212
import io.element.android.libraries.core.extensions.mapFailure
13+
import io.element.android.libraries.featureflag.api.FeatureFlagService
1314
import io.element.android.libraries.matrix.api.core.DeviceId
1415
import io.element.android.libraries.matrix.api.core.EventId
1516
import io.element.android.libraries.matrix.api.core.ProgressCallback
@@ -103,6 +104,7 @@ class RustMatrixRoom(
103104
private val roomContentForwarder: RoomContentForwarder,
104105
private val roomSyncSubscriber: RoomSyncSubscriber,
105106
private val matrixRoomInfoMapper: MatrixRoomInfoMapper,
107+
private val featureFlagService: FeatureFlagService,
106108
) : MatrixRoom {
107109
override val roomId = RoomId(innerRoom.id())
108110

@@ -700,6 +702,7 @@ class RustMatrixRoom(
700702
dispatcher = roomDispatcher,
701703
roomContentForwarder = roomContentForwarder,
702704
onNewSyncedEvent = onNewSyncedEvent,
705+
featureFlagsService = featureFlagService,
703706
)
704707
}
705708
}

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustRoomFactory.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package io.element.android.libraries.matrix.impl.room
1010
import androidx.collection.lruCache
1111
import io.element.android.appconfig.TimelineConfig
1212
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
13+
import io.element.android.libraries.featureflag.api.FeatureFlagService
1314
import io.element.android.libraries.matrix.api.core.DeviceId
1415
import io.element.android.libraries.matrix.api.core.RoomId
1516
import io.element.android.libraries.matrix.api.core.SessionId
@@ -49,6 +50,7 @@ class RustRoomFactory(
4950
private val innerRoomListService: InnerRoomListService,
5051
private val roomSyncSubscriber: RoomSyncSubscriber,
5152
private val timelineEventTypeFilterFactory: TimelineEventTypeFilterFactory,
53+
private val featureFlagService: FeatureFlagService,
5254
) {
5355
@OptIn(ExperimentalCoroutinesApi::class)
5456
private val dispatcher = dispatchers.io.limitedParallelism(1)
@@ -117,6 +119,7 @@ class RustRoomFactory(
117119
roomContentForwarder = roomContentForwarder,
118120
roomSyncSubscriber = roomSyncSubscriber,
119121
matrixRoomInfoMapper = matrixRoomInfoMapper,
122+
featureFlagService = featureFlagService,
120123
)
121124
}
122125
}

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
package io.element.android.libraries.matrix.impl.timeline
99

10+
import io.element.android.libraries.featureflag.api.FeatureFlagService
11+
import io.element.android.libraries.featureflag.api.FeatureFlags
1012
import io.element.android.libraries.matrix.api.core.EventId
1113
import io.element.android.libraries.matrix.api.core.ProgressCallback
1214
import io.element.android.libraries.matrix.api.core.RoomId
@@ -85,6 +87,7 @@ class RustTimeline(
8587
private val coroutineScope: CoroutineScope,
8688
private val dispatcher: CoroutineDispatcher,
8789
private val roomContentForwarder: RoomContentForwarder,
90+
private val featureFlagsService: FeatureFlagService,
8891
onNewSyncedEvent: () -> Unit,
8992
) : Timeline {
9093
private val initLatch = CompletableDeferred<Unit>()
@@ -330,6 +333,7 @@ class RustTimeline(
330333
formattedCaption: String?,
331334
progressCallback: ProgressCallback?,
332335
): Result<MediaUploadHandler> {
336+
val useSendQueue = featureFlagsService.isFeatureEnabled(FeatureFlags.MediaUploadOnSendQueue)
333337
return sendAttachment(listOfNotNull(file, thumbnailFile)) {
334338
inner.sendImage(
335339
url = file.path,
@@ -339,7 +343,7 @@ class RustTimeline(
339343
formattedCaption = formattedCaption?.let {
340344
FormattedBody(body = it, format = MessageFormat.Html)
341345
},
342-
storeInCache = true,
346+
useSendQueue = useSendQueue,
343347
progressWatcher = progressCallback?.toProgressWatcher()
344348
)
345349
}
@@ -353,6 +357,7 @@ class RustTimeline(
353357
formattedCaption: String?,
354358
progressCallback: ProgressCallback?,
355359
): Result<MediaUploadHandler> {
360+
val useSendQueue = featureFlagsService.isFeatureEnabled(FeatureFlags.MediaUploadOnSendQueue)
356361
return sendAttachment(listOfNotNull(file, thumbnailFile)) {
357362
inner.sendVideo(
358363
url = file.path,
@@ -362,29 +367,36 @@ class RustTimeline(
362367
formattedCaption = formattedCaption?.let {
363368
FormattedBody(body = it, format = MessageFormat.Html)
364369
},
365-
storeInCache = true,
370+
useSendQueue = useSendQueue,
366371
progressWatcher = progressCallback?.toProgressWatcher()
367372
)
368373
}
369374
}
370375

371376
override suspend fun sendAudio(file: File, audioInfo: AudioInfo, progressCallback: ProgressCallback?): Result<MediaUploadHandler> {
377+
val useSendQueue = featureFlagsService.isFeatureEnabled(FeatureFlags.MediaUploadOnSendQueue)
372378
return sendAttachment(listOf(file)) {
373379
inner.sendAudio(
374380
url = file.path,
375381
audioInfo = audioInfo.map(),
376382
// Maybe allow a caption in the future?
377383
caption = null,
378384
formattedCaption = null,
379-
storeInCache = true,
385+
useSendQueue = useSendQueue,
380386
progressWatcher = progressCallback?.toProgressWatcher()
381387
)
382388
}
383389
}
384390

385391
override suspend fun sendFile(file: File, fileInfo: FileInfo, progressCallback: ProgressCallback?): Result<MediaUploadHandler> {
392+
val useSendQueue = featureFlagsService.isFeatureEnabled(FeatureFlags.MediaUploadOnSendQueue)
386393
return sendAttachment(listOf(file)) {
387-
inner.sendFile(file.path, fileInfo.map(), false, progressCallback?.toProgressWatcher())
394+
inner.sendFile(
395+
url = file.path,
396+
fileInfo = fileInfo.map(),
397+
useSendQueue = useSendQueue,
398+
progressWatcher = progressCallback?.toProgressWatcher(),
399+
)
388400
}
389401
}
390402

@@ -491,17 +503,20 @@ class RustTimeline(
491503
audioInfo: AudioInfo,
492504
waveform: List<Float>,
493505
progressCallback: ProgressCallback?,
494-
): Result<MediaUploadHandler> = sendAttachment(listOf(file)) {
495-
inner.sendVoiceMessage(
496-
url = file.path,
497-
audioInfo = audioInfo.map(),
498-
waveform = waveform.toMSC3246range(),
499-
// Maybe allow a caption in the future?
500-
caption = null,
501-
formattedCaption = null,
502-
storeInCache = true,
503-
progressWatcher = progressCallback?.toProgressWatcher(),
504-
)
506+
): Result<MediaUploadHandler> {
507+
val useSendQueue = featureFlagsService.isFeatureEnabled(FeatureFlags.MediaUploadOnSendQueue)
508+
return sendAttachment(listOf(file)) {
509+
inner.sendVoiceMessage(
510+
url = file.path,
511+
audioInfo = audioInfo.map(),
512+
waveform = waveform.toMSC3246range(),
513+
// Maybe allow a caption in the future?
514+
caption = null,
515+
formattedCaption = null,
516+
useSendQueue = useSendQueue,
517+
progressWatcher = progressCallback?.toProgressWatcher(),
518+
)
519+
}
505520
}
506521

507522
private fun sendAttachment(files: List<File>, handle: () -> SendAttachmentJoinHandle): Result<MediaUploadHandler> {

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/item/event/EventTimelineItemMapper.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ fun RustEventSendState?.map(): LocalEventSendState? {
100100
LocalEventSendState.Failed.Unknown(queueWedgeError.msg)
101101
}
102102
}
103+
is QueueWedgeError.InvalidMimeType -> {
104+
LocalEventSendState.Failed.InvalidMimeType(queueWedgeError.mimeType)
105+
}
106+
is QueueWedgeError.MissingMediaContent -> {
107+
LocalEventSendState.Failed.MissingMediaContent
108+
}
103109
}
104110
}
105111
is RustEventSendState.Sent -> LocalEventSendState.Sent(EventId(eventId))

libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClientTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package io.element.android.libraries.matrix.impl
99

1010
import com.google.common.truth.Truth.assertThat
11+
import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
1112
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeRustClient
1213
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeRustSyncService
1314
import io.element.android.libraries.matrix.impl.room.FakeTimelineEventTypeFilterFactory
@@ -46,5 +47,6 @@ class RustMatrixClientTest {
4647
baseCacheDirectory = File(""),
4748
clock = FakeSystemClock(),
4849
timelineEventTypeFilterFactory = FakeTimelineEventTypeFilterFactory(),
50+
featureFlagService = FakeFeatureFlagService(),
4951
)
5052
}

0 commit comments

Comments
 (0)