Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SDK bindings version to 0.2.62 and fix SendHandle usages #3876

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ class ResolveVerifiedUserSendFailurePresenter @Inject constructor(
is ResolveVerifiedUserSendFailureEvents.ComputeForMessage -> {
val sendState = event.messageEvent.localSendState as? LocalEventSendState.Failed.VerifiedUser
val transactionId = event.messageEvent.transactionId
resolver = if (sendState != null && transactionId != null) {
val sendHandle = event.messageEvent.sendhandle
resolver = if (sendState != null && transactionId != null && sendHandle != null) {
VerifiedUserSendFailureResolver(
room = room,
transactionId = transactionId,
sendHandle = sendHandle,
iterator = VerifiedUserSendFailureIterator.from(sendState)
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package io.element.android.features.messages.impl.crypto.sendfailure.resolve

import androidx.compose.runtime.mutableStateOf
import io.element.android.libraries.matrix.api.core.SendHandle
import io.element.android.libraries.matrix.api.core.TransactionId
import io.element.android.libraries.matrix.api.room.MatrixRoom
import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState
Expand All @@ -22,6 +23,7 @@ import timber.log.Timber
class VerifiedUserSendFailureResolver(
private val room: MatrixRoom,
private val transactionId: TransactionId,
private val sendHandle: SendHandle,
private val iterator: VerifiedUserSendFailureIterator,
) {
val currentSendFailure = mutableStateOf<LocalEventSendState.Failed.VerifiedUser?>(null)
Expand All @@ -33,7 +35,7 @@ class VerifiedUserSendFailureResolver(
}

suspend fun resend(): Result<Unit> {
return room.retrySendMessage(transactionId)
return sendHandle.retry()
.onSuccess {
Timber.d("Succeed to resend message with transactionId: $transactionId")
currentSendFailure.value = null
Expand All @@ -46,10 +48,10 @@ class VerifiedUserSendFailureResolver(
suspend fun resolveAndResend(): Result<Unit> {
return when (val failure = currentSendFailure.value) {
is LocalEventSendState.Failed.VerifiedUserHasUnsignedDevice -> {
room.ignoreDeviceTrustAndResend(failure.devices, transactionId)
room.ignoreDeviceTrustAndResend(failure.devices, sendHandle)
}
is LocalEventSendState.Failed.VerifiedUserChangedIdentity -> {
room.withdrawVerificationAndResend(failure.users, transactionId)
room.withdrawVerificationAndResend(failure.users, sendHandle)
}
else -> {
Result.failure(IllegalStateException("Unknown send failure type"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ internal fun aTimelineItemEvent(
origin = null,
timelineItemDebugInfoProvider = { debugInfo },
messageShieldProvider = { messageShield },
sendHandleProvider = { null }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class TimelineItemEventFactory @AssistedInject constructor(
origin = currentTimelineItem.event.origin,
timelineItemDebugInfoProvider = currentTimelineItem.event.timelineItemDebugInfoProvider,
messageShieldProvider = currentTimelineItem.event.messageShieldProvider,
sendHandleProvider = currentTimelineItem.event.sendHandleProvider,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.element.android.features.messages.impl.timeline.model.event.TimelineIt
import io.element.android.features.messages.impl.timeline.model.virtual.TimelineItemVirtualModel
import io.element.android.libraries.designsystem.components.avatar.AvatarData
import io.element.android.libraries.matrix.api.core.EventId
import io.element.android.libraries.matrix.api.core.SendHandle
import io.element.android.libraries.matrix.api.core.TransactionId
import io.element.android.libraries.matrix.api.core.UniqueId
import io.element.android.libraries.matrix.api.core.UserId
Expand All @@ -25,6 +26,7 @@ import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSen
import io.element.android.libraries.matrix.api.timeline.item.event.MessageShield
import io.element.android.libraries.matrix.api.timeline.item.event.MessageShieldProvider
import io.element.android.libraries.matrix.api.timeline.item.event.ProfileTimelineDetails
import io.element.android.libraries.matrix.api.timeline.item.event.SendHandleProvider
import io.element.android.libraries.matrix.api.timeline.item.event.TimelineItemDebugInfoProvider
import io.element.android.libraries.matrix.api.timeline.item.event.TimelineItemEventOrigin
import io.element.android.libraries.matrix.api.timeline.item.event.getDisambiguatedDisplayName
Expand Down Expand Up @@ -82,6 +84,7 @@ sealed interface TimelineItem {
val origin: TimelineItemEventOrigin?,
val timelineItemDebugInfoProvider: TimelineItemDebugInfoProvider,
val messageShieldProvider: MessageShieldProvider,
val sendHandleProvider: SendHandleProvider,
) : TimelineItem {
val showSenderInformation = groupPosition.isNew() && !isMine

Expand Down Expand Up @@ -114,6 +117,8 @@ sealed interface TimelineItem {

val debugInfo: TimelineItemDebugInfo
get() = timelineItemDebugInfoProvider()

val sendhandle: SendHandle? get() = sendHandleProvider()
}

@Immutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ class ResolveVerifiedUserSendFailurePresenterTest {
userDisplayNameResult = { userId ->
Result.success(userId.value)
},
retrySendMessageResult = {
Result.success(Unit)
},
)
val presenter = createResolveVerifiedUserSendFailurePresenter(room)
presenter.test {
Expand Down Expand Up @@ -219,9 +216,6 @@ class ResolveVerifiedUserSendFailurePresenterTest {
userDisplayNameResult = { userId ->
Result.success(userId.value)
},
retrySendMessageResult = {
Result.success(Unit)
},
)
val presenter = createResolveVerifiedUserSendFailurePresenter(room)
presenter.test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import io.element.android.libraries.designsystem.components.avatar.AvatarSize
import io.element.android.libraries.matrix.api.core.EventId
import io.element.android.libraries.matrix.api.core.TransactionId
import io.element.android.libraries.matrix.api.core.UniqueId
import io.element.android.libraries.matrix.api.timeline.item.TimelineItemDebugInfo
import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState
import io.element.android.libraries.matrix.api.timeline.item.event.MessageShield
import io.element.android.libraries.matrix.api.timeline.item.event.MessageShieldProvider
import io.element.android.libraries.matrix.api.timeline.item.event.SendHandleProvider
import io.element.android.libraries.matrix.api.timeline.item.event.TimelineItemDebugInfoProvider
import io.element.android.libraries.matrix.test.AN_EVENT_ID
import io.element.android.libraries.matrix.test.A_MESSAGE
import io.element.android.libraries.matrix.test.A_USER_ID
import io.element.android.libraries.matrix.test.A_USER_NAME
import io.element.android.libraries.matrix.test.core.FakeSendHandle
import io.element.android.libraries.matrix.ui.messages.reply.InReplyToDetails
import io.element.android.libraries.matrix.ui.messages.reply.aProfileTimelineDetailsReady
import kotlinx.collections.immutable.toImmutableList
Expand All @@ -39,9 +41,10 @@ internal fun aMessageEvent(
content: TimelineItemEventContent = TimelineItemTextContent(body = A_MESSAGE, htmlDocument = null, formattedBody = null, isEdited = false),
inReplyTo: InReplyToDetails? = null,
isThreaded: Boolean = false,
debugInfo: TimelineItemDebugInfo = aTimelineItemDebugInfo(),
sendState: LocalEventSendState = LocalEventSendState.Sent(AN_EVENT_ID),
messageShield: MessageShield? = null,
debugInfoProvider: TimelineItemDebugInfoProvider = TimelineItemDebugInfoProvider { aTimelineItemDebugInfo() },
messageShieldProvider: MessageShieldProvider = MessageShieldProvider { null },
sendHandleProvider: SendHandleProvider = SendHandleProvider { FakeSendHandle() }
) = TimelineItem.Event(
id = UniqueId(eventId?.value.orEmpty()),
eventId = eventId,
Expand All @@ -60,6 +63,7 @@ internal fun aMessageEvent(
inReplyTo = inReplyTo,
isThreaded = isThreaded,
origin = null,
timelineItemDebugInfoProvider = { debugInfo },
messageShieldProvider = { messageShield },
timelineItemDebugInfoProvider = debugInfoProvider,
messageShieldProvider = messageShieldProvider,
sendHandleProvider = sendHandleProvider,
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.element.android.libraries.matrix.api.core.UniqueId
import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState
import io.element.android.libraries.matrix.test.AN_EVENT_ID
import io.element.android.libraries.matrix.test.A_USER_ID
import io.element.android.libraries.matrix.test.core.FakeSendHandle
import io.element.android.libraries.matrix.ui.messages.reply.aProfileTimelineDetailsReady
import kotlinx.collections.immutable.toImmutableList
import org.junit.Test
Expand All @@ -44,6 +45,7 @@ class TimelineItemGrouperTest {
origin = null,
timelineItemDebugInfoProvider = { aTimelineItemDebugInfo() },
messageShieldProvider = { null },
sendHandleProvider = { FakeSendHandle() },
)
private val aNonGroupableItem = aMessageEvent()
private val aNonGroupableItemNoEvent = TimelineItem.Virtual(UniqueId("virtual"), aTimelineItemDaySeparatorModel("Today"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import io.element.android.libraries.matrix.api.timeline.item.event.RedactedConte
import io.element.android.libraries.matrix.test.AN_EVENT_ID
import io.element.android.libraries.matrix.test.AN_EVENT_ID_2
import io.element.android.libraries.matrix.test.A_USER_ID
import io.element.android.libraries.matrix.test.core.FakeSendHandle
import io.element.android.libraries.mediaplayer.api.MediaPlayer
import io.element.android.libraries.mediaplayer.test.FakeMediaPlayer
import io.element.android.tests.testutils.testCoroutineDispatchers
Expand Down Expand Up @@ -96,6 +97,7 @@ fun aRedactedMatrixTimeline(eventId: EventId) = listOf<MatrixTimelineItem>(
)
},
messageShieldProvider = { null },
sendHandleProvider = { FakeSendHandle() },
),
)
)
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ jsoup = "org.jsoup:jsoup:1.18.1"
appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" }
molecule-runtime = "app.cash.molecule:molecule-runtime:2.0.0"
timber = "com.jakewharton.timber:timber:5.0.1"
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.2.61"
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.2.62"
matrix_richtexteditor = { module = "io.element.android:wysiwyg", version.ref = "wysiwyg" }
matrix_richtexteditor_compose = { module = "io.element.android:wysiwyg-compose", version.ref = "wysiwyg" }
sqldelight-driver-android = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright 2024 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only
* Please see LICENSE in the repository root for full details.
*/

package io.element.android.libraries.matrix.api.core

fun interface SendHandle {
suspend fun retry(): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.element.android.libraries.matrix.api.core.EventId
import io.element.android.libraries.matrix.api.core.ProgressCallback
import io.element.android.libraries.matrix.api.core.RoomAlias
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.core.SendHandle
import io.element.android.libraries.matrix.api.core.SessionId
import io.element.android.libraries.matrix.api.core.TransactionId
import io.element.android.libraries.matrix.api.core.UserId
Expand Down Expand Up @@ -154,8 +155,6 @@ interface MatrixRoom : Closeable {

suspend fun forwardEvent(eventId: EventId, roomIds: List<RoomId>): Result<Unit>

suspend fun retrySendMessage(transactionId: TransactionId): Result<Unit>

suspend fun cancelSend(transactionId: TransactionId): Result<Unit>

suspend fun leave(): Result<Unit>
Expand Down Expand Up @@ -356,20 +355,20 @@ interface MatrixRoom : Closeable {
* Ignore the local trust for the given devices and resend messages that failed to send because said devices are unverified.
*
* @param devices The map of users identifiers to device identifiers received in the error
* @param transactionId The send queue transaction identifier of the local echo the send error applies to.
* @param sendHandle The send queue handle of the local echo the send error applies to. It can be used to retry the upload.
*
*/
suspend fun ignoreDeviceTrustAndResend(devices: Map<UserId, List<DeviceId>>, transactionId: TransactionId): Result<Unit>
suspend fun ignoreDeviceTrustAndResend(devices: Map<UserId, List<DeviceId>>, sendHandle: SendHandle): Result<Unit>

/**
* Remove verification requirements for the given users and
* resend messages that failed to send because their identities were no longer verified.
*
* @param userIds The list of users identifiers received in the error.
* @param transactionId The send queue transaction identifier of the local echo the send error applies to.
* @param sendHandle The send queue handle of the local echo the send error applies to. It can be used to retry the upload.
*
*/
suspend fun withdrawVerificationAndResend(userIds: List<UserId>, transactionId: TransactionId): Result<Unit>
suspend fun withdrawVerificationAndResend(userIds: List<UserId>, sendHandle: SendHandle): Result<Unit>

override fun close() = destroy()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package io.element.android.libraries.matrix.api.timeline.item.event

import io.element.android.libraries.matrix.api.core.EventId
import io.element.android.libraries.matrix.api.core.SendHandle
import io.element.android.libraries.matrix.api.core.TransactionId
import io.element.android.libraries.matrix.api.core.UserId
import io.element.android.libraries.matrix.api.timeline.item.TimelineItemDebugInfo
Expand All @@ -30,6 +31,7 @@ data class EventTimelineItem(
val origin: TimelineItemEventOrigin?,
val timelineItemDebugInfoProvider: TimelineItemDebugInfoProvider,
val messageShieldProvider: MessageShieldProvider,
val sendHandleProvider: SendHandleProvider,
) {
fun inReplyTo(): InReplyTo? {
return (content as? MessageContent)?.inReplyTo
Expand All @@ -52,3 +54,7 @@ fun interface TimelineItemDebugInfoProvider {
fun interface MessageShieldProvider {
operator fun invoke(strict: Boolean): MessageShield?
}

fun interface SendHandleProvider {
operator fun invoke(): SendHandle?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2024 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only
* Please see LICENSE in the repository root for full details.
*/

package io.element.android.libraries.matrix.impl.core

import io.element.android.libraries.matrix.api.core.SendHandle

class RustSendHandle(
val inner: org.matrix.rustcomponents.sdk.SendHandle,
) : SendHandle {
override suspend fun retry(): Result<Unit> {
return runCatching {
inner.tryResend()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
package io.element.android.libraries.matrix.impl.room

import io.element.android.libraries.matrix.api.room.RoomType
import org.matrix.rustcomponents.sdk.RoomType as RustRoomType

fun String?.toRoomType(): RoomType {
fun RustRoomType.map(): RoomType {
return when (this) {
null -> RoomType.Room
"m.space" -> RoomType.Space
else -> RoomType.Other(this)
RustRoomType.Room -> RoomType.Room
RustRoomType.Space -> RoomType.Space
is RustRoomType.Custom -> RoomType.Other(this.value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.element.android.libraries.matrix.api.core.EventId
import io.element.android.libraries.matrix.api.core.ProgressCallback
import io.element.android.libraries.matrix.api.core.RoomAlias
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.core.SendHandle
import io.element.android.libraries.matrix.api.core.SessionId
import io.element.android.libraries.matrix.api.core.TransactionId
import io.element.android.libraries.matrix.api.core.UserId
Expand Down Expand Up @@ -45,6 +46,7 @@ import io.element.android.libraries.matrix.api.timeline.Timeline
import io.element.android.libraries.matrix.api.timeline.item.event.EventOrTransactionId
import io.element.android.libraries.matrix.api.widget.MatrixWidgetDriver
import io.element.android.libraries.matrix.api.widget.MatrixWidgetSettings
import io.element.android.libraries.matrix.impl.core.RustSendHandle
import io.element.android.libraries.matrix.impl.mapper.map
import io.element.android.libraries.matrix.impl.room.draft.into
import io.element.android.libraries.matrix.impl.room.member.RoomMemberListFetcher
Expand Down Expand Up @@ -481,10 +483,6 @@ class RustMatrixRoom(
return liveTimeline.forwardEvent(eventId, roomIds)
}

override suspend fun retrySendMessage(transactionId: TransactionId): Result<Unit> = runCatching {
innerRoom.tryResend(transactionId.value)
}

override suspend fun cancelSend(transactionId: TransactionId): Result<Unit> {
return liveTimeline.cancelSend(transactionId)
}
Expand Down Expand Up @@ -671,19 +669,19 @@ class RustMatrixRoom(
innerRoom.clearComposerDraft()
}

override suspend fun ignoreDeviceTrustAndResend(devices: Map<UserId, List<DeviceId>>, transactionId: TransactionId) = runCatching {
override suspend fun ignoreDeviceTrustAndResend(devices: Map<UserId, List<DeviceId>>, sendHandle: SendHandle) = runCatching {
innerRoom.ignoreDeviceTrustAndResend(
devices = devices.entries.associate { entry ->
entry.key.value to entry.value.map { it.value }
},
transactionId = transactionId.value
sendHandle = (sendHandle as RustSendHandle).inner,
)
}

override suspend fun withdrawVerificationAndResend(userIds: List<UserId>, transactionId: TransactionId) = runCatching {
override suspend fun withdrawVerificationAndResend(userIds: List<UserId>, sendHandle: SendHandle) = runCatching {
innerRoom.withdrawVerificationAndResend(
userIds = userIds.map { it.value },
transactionId = transactionId.value
sendHandle = (sendHandle as RustSendHandle).inner,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package io.element.android.libraries.matrix.impl.room.preview
import io.element.android.libraries.matrix.api.core.RoomAlias
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.room.preview.RoomPreviewInfo
import io.element.android.libraries.matrix.impl.room.toRoomType
import io.element.android.libraries.matrix.impl.room.map
import org.matrix.rustcomponents.sdk.JoinRule
import org.matrix.rustcomponents.sdk.Membership
import org.matrix.rustcomponents.sdk.RoomPreviewInfo as RustRoomPreviewInfo
Expand All @@ -24,7 +24,7 @@ object RoomPreviewInfoMapper {
topic = info.topic,
avatarUrl = info.avatarUrl,
numberOfJoinedMembers = info.numJoinedMembers.toLong(),
roomType = info.roomType.toRoomType(),
roomType = info.roomType.map(),
isHistoryWorldReadable = info.isHistoryWorldReadable,
isJoined = info.membership == Membership.JOINED,
isInvited = info.membership == Membership.INVITED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class RustRoomDirectoryList(

override suspend fun filter(filter: String?, batchSize: Int, viaServerName: String?): Result<Unit> {
return execute {
inner.search(filter = filter, batchSize = batchSize.toUInt(), viaServerName = viaServerName)
inner.search(filter = filter, batchSize = batchSize.toUInt(), viaServerName = null)
}
}

Expand Down
Loading
Loading