Skip to content

Commit

Permalink
Update dependency org.matrix.rustcomponents:sdk-android to v0.2.50 (#…
Browse files Browse the repository at this point in the history
…3565)

* Adapt to changes in the SDK

* Update dependency org.matrix.rustcomponents:sdk-android to v0.2.50

* Use lambda instead of overriding the `EventDebugInfoProvider` interface

* Fix test proposal.
We may find a better way to compare data class instance if we need to do more comparison in the future...

---------

Co-authored-by: Jorge Martín <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Benoit Marty <[email protected]>
  • Loading branch information
3 people authored Oct 1, 2024
1 parent 249104b commit 3001efb
Show file tree
Hide file tree
Showing 26 changed files with 216 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ internal fun aTimelineItemEvent(
groupPosition = groupPosition,
localSendState = sendState,
inReplyTo = inReplyTo,
debugInfo = debugInfo,
debugInfoProvider = { debugInfo },
isThreaded = isThreaded,
origin = null,
messageShield = messageShield,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ class TimelineItemEventFactory @AssistedInject constructor(
localSendState = currentTimelineItem.event.localSendState,
inReplyTo = currentTimelineItem.event.inReplyTo()?.map(permalinkParser = permalinkParser),
isThreaded = currentTimelineItem.event.isThreaded(),
debugInfo = currentTimelineItem.event.debugInfo,
debugInfoProvider = currentTimelineItem.event.debugInfoProvider,
origin = currentTimelineItem.event.origin,
messageShield = currentTimelineItem.event.messageShield,
messageShield = currentTimelineItem.event.messageShieldProvider.getShield(strict = false)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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.core.UserId
import io.element.android.libraries.matrix.api.timeline.item.TimelineItemDebugInfo
import io.element.android.libraries.matrix.api.timeline.item.event.EventDebugInfoProvider
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.ProfileTimelineDetails
Expand Down Expand Up @@ -74,7 +74,7 @@ sealed interface TimelineItem {
val localSendState: LocalEventSendState?,
val inReplyTo: InReplyToDetails?,
val isThreaded: Boolean,
val debugInfo: TimelineItemDebugInfo,
val debugInfoProvider: EventDebugInfoProvider,
val origin: TimelineItemEventOrigin?,
val messageShield: MessageShield?,
) : TimelineItem {
Expand All @@ -89,6 +89,8 @@ sealed interface TimelineItem {
val isSticker: Boolean = content is TimelineItemStickerContent

val isRemote = eventId != null

val debugInfo = debugInfoProvider.get()
}

@Immutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ class MessagesPresenterTest {
canUserPinUnpinResult = { Result.success(true) },
)

val redactEventLambda = lambdaRecorder { _: EventId?, _: TransactionId?, _: String? -> Result.success(true) }
val redactEventLambda = lambdaRecorder { _: EventId?, _: TransactionId?, _: String? -> Result.success(Unit) }
liveTimeline.redactEventLambda = redactEventLambda

val presenter = createMessagesPresenter(matrixRoom = matrixRoom, coroutineDispatchers = coroutineDispatchers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal fun aMessageEvent(
readReceiptState = TimelineItemReadReceipts(emptyList<ReadReceiptData>().toImmutableList()),
localSendState = sendState,
inReplyTo = inReplyTo,
debugInfo = debugInfo,
debugInfoProvider = { debugInfo },
isThreaded = isThreaded,
origin = null,
messageShield = messageShield,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TimelineItemGrouperTest {
canBeRepliedTo = false,
inReplyTo = null,
isThreaded = false,
debugInfo = aTimelineItemDebugInfo(),
debugInfoProvider = { aTimelineItemDebugInfo() },
origin = null,
messageShield = null,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ fun aRedactedMatrixTimeline(eventId: EventId) = listOf<MatrixTimelineItem>(
senderProfile = ProfileTimelineDetails.Unavailable,
timestamp = 9442,
content = RedactedContent,
debugInfo = TimelineItemDebugInfo(
model = "enim",
originalJson = null,
latestEditedJson = null
),
debugInfoProvider = {
TimelineItemDebugInfo(
model = "enim",
originalJson = null,
latestEditedJson = null
)
},
origin = null,
messageShield = null,
messageShieldProvider = { null },
),
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class PollRepository @Inject constructor(

suspend fun deletePoll(
pollStartId: EventId,
): Result<Boolean> =
): Result<Unit> =
timelineProvider
.getActiveTimeline()
.redactEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class CreatePollPresenterTest {
@Test
fun `delete confirms`() = runTest {
val presenter = createCreatePollPresenter(mode = CreatePollMode.EditPoll(pollEventId))
val redactEventLambda = lambdaRecorder { _: EventId?, _: TransactionId?, _: String? -> Result.success(true) }
val redactEventLambda = lambdaRecorder { _: EventId?, _: TransactionId?, _: String? -> Result.success(Unit) }
timeline.redactEventLambda = redactEventLambda
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
Expand All @@ -481,7 +481,7 @@ class CreatePollPresenterTest {
@Test
fun `delete can be cancelled`() = runTest {
val presenter = createCreatePollPresenter(mode = CreatePollMode.EditPoll(pollEventId))
val redactEventLambda = lambdaRecorder { _: EventId?, _: TransactionId?, _: String? -> Result.success(true) }
val redactEventLambda = lambdaRecorder { _: EventId?, _: TransactionId?, _: String? -> Result.success(Unit) }
timeline.redactEventLambda = redactEventLambda
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
Expand All @@ -499,7 +499,7 @@ class CreatePollPresenterTest {
@Test
fun `delete can be confirmed`() = runTest {
val presenter = createCreatePollPresenter(mode = CreatePollMode.EditPoll(pollEventId))
val redactEventLambda = lambdaRecorder { _: EventId?, _: TransactionId?, _: String? -> Result.success(true) }
val redactEventLambda = lambdaRecorder { _: EventId?, _: TransactionId?, _: String? -> Result.success(Unit) }
timeline.redactEventLambda = redactEventLambda
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,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.49"
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.2.50"
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
Expand Up @@ -154,7 +154,7 @@ interface MatrixRoom : Closeable {

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

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

suspend fun leave(): Result<Unit>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ interface Timeline : AutoCloseable {
progressCallback: ProgressCallback?
): Result<MediaUploadHandler>

suspend fun redactEvent(eventId: EventId?, transactionId: TransactionId?, reason: String?): Result<Boolean>
suspend fun redactEvent(eventId: EventId?, transactionId: TransactionId?, reason: String?): Result<Unit>

suspend fun sendAudio(file: File, audioInfo: AudioInfo, progressCallback: ProgressCallback?): Result<MediaUploadHandler>

Expand All @@ -99,7 +99,7 @@ interface Timeline : AutoCloseable {

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

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

/**
* Share a location message in the room.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ data class EventTimelineItem(
val senderProfile: ProfileTimelineDetails,
val timestamp: Long,
val content: EventContent,
val debugInfo: TimelineItemDebugInfo,
val debugInfoProvider: EventDebugInfoProvider,
val origin: TimelineItemEventOrigin?,
val messageShield: MessageShield?,
val messageShieldProvider: EventShieldsProvider,
) {
fun inReplyTo(): InReplyTo? {
return (content as? MessageContent)?.inReplyTo
Expand All @@ -45,3 +45,11 @@ data class EventTimelineItem(
return details is InReplyTo.NotLoaded
}
}

fun interface EventDebugInfoProvider {
fun get(): TimelineItemDebugInfo
}

fun interface EventShieldsProvider {
fun getShield(strict: Boolean): MessageShield?
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ internal class RustEncryptionService(
override fun onUpdate(status: RustEnableRecoveryProgress) {
enableRecoveryProgressStateFlow.value = enableRecoveryProgressMapper.map(status)
}
}
},
passphrase = null,
)
// enableRecovery returns the encryption key, but we read it from the state flow
.let { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.withTimeout
import org.matrix.rustcomponents.sdk.RoomListService
import org.matrix.rustcomponents.sdk.Timeline
import org.matrix.rustcomponents.sdk.TimelineItemContent
import org.matrix.rustcomponents.sdk.contentWithoutRelationFromMessage
import kotlin.time.Duration.Companion.milliseconds

/**
Expand All @@ -40,11 +42,7 @@ class RoomContentForwarder(
toRoomIds: List<RoomId>,
timeoutMs: Long = 5000L
) {
val content = fromTimeline
.getEventTimelineItemByEventId(eventId.value)
.content()
.asMessage()
?.content()
val content = (fromTimeline.getEventTimelineItemByEventId(eventId.value).content as? TimelineItemContent.Message)?.content
?: throw ForwardEventException(toRoomIds)

val targetSlidingSyncRooms = toRoomIds.mapNotNull { roomId -> roomListService.roomOrNull(roomId.value) }
Expand All @@ -58,7 +56,7 @@ class RoomContentForwarder(
// Sending a message requires a registered timeline listener
targetRoom.timeline().runWithTimelineListenerRegistered {
withTimeout(timeoutMs.milliseconds) {
targetRoom.timeline().send(content)
targetRoom.timeline().send(contentWithoutRelationFromMessage(content))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ class RustMatrixRoom(
innerRoom.tryResend(transactionId.value)
}

override suspend fun cancelSend(transactionId: TransactionId): Result<Boolean> {
override suspend fun cancelSend(transactionId: TransactionId): Result<Unit> {
return liveTimeline.cancelSend(transactionId)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.matrix.rustcomponents.sdk.EditedContent
import org.matrix.rustcomponents.sdk.EventOrTransactionId
import org.matrix.rustcomponents.sdk.EventTimelineItem
import org.matrix.rustcomponents.sdk.FormattedBody
import org.matrix.rustcomponents.sdk.MessageFormat
Expand Down Expand Up @@ -274,11 +275,14 @@ class RustTimeline(
}
}

override suspend fun redactEvent(eventId: EventId?, transactionId: TransactionId?, reason: String?): Result<Boolean> = withContext(dispatcher) {
override suspend fun redactEvent(eventId: EventId?, transactionId: TransactionId?, reason: String?): Result<Unit> = withContext(dispatcher) {
runCatching {
getEventTimelineItem(eventId, transactionId).use { item ->
inner.redactEvent(item = item, reason = reason)
val eventOrTransactionId = if (eventId != null) {
EventOrTransactionId.EventId(eventId.value)
} else {
EventOrTransactionId.TransactionId(transactionId!!.value)
}
inner.redactEvent(eventOrTransactionId = eventOrTransactionId, reason = reason)
}
}

Expand All @@ -291,19 +295,22 @@ class RustTimeline(
): Result<Unit> =
withContext(dispatcher) {
runCatching<Unit> {
getEventTimelineItem(originalEventId, transactionId).use { item ->
val editedContent = EditedContent.RoomMessage(
content = MessageEventContent.from(
body = body,
htmlBody = htmlBody,
intentionalMentions = intentionalMentions
),
)
inner.edit(
newContent = editedContent,
item = item,
)
val eventOrTransactionId = if (originalEventId != null) {
EventOrTransactionId.EventId(originalEventId.value)
} else {
EventOrTransactionId.TransactionId(transactionId!!.value)
}
val editedContent = EditedContent.RoomMessage(
content = MessageEventContent.from(
body = body,
htmlBody = htmlBody,
intentionalMentions = intentionalMentions
),
)
inner.edit(
newContent = editedContent,
eventOrTransactionId = eventOrTransactionId,
)
}
}

Expand Down Expand Up @@ -343,6 +350,7 @@ class RustTimeline(
}

@Throws
@Suppress("UnusedPrivateMember")
private suspend fun getEventTimelineItem(eventId: EventId?, transactionId: TransactionId?): EventTimelineItem {
return try {
when {
Expand Down Expand Up @@ -411,7 +419,8 @@ class RustTimeline(
}
}

override suspend fun cancelSend(transactionId: TransactionId): Result<Boolean> = redactEvent(eventId = null, transactionId = transactionId, reason = null)
override suspend fun cancelSend(transactionId: TransactionId): Result<Unit> =
redactEvent(eventId = null, transactionId = transactionId, reason = null)

override suspend fun sendLocation(
body: String,
Expand Down Expand Up @@ -455,10 +464,6 @@ class RustTimeline(
pollKind: PollKind,
): Result<Unit> = withContext(dispatcher) {
runCatching {
val pollStartEvent =
inner.getEventTimelineItemByEventId(
eventId = pollStartId.value
)
val editedContent = EditedContent.PollStart(
pollData = PollData(
question = question,
Expand All @@ -467,12 +472,10 @@ class RustTimeline(
pollKind = pollKind.toInner(),
),
)
pollStartEvent.use {
inner.edit(
newContent = editedContent,
item = it,
)
}
inner.edit(
newContent = editedContent,
eventOrTransactionId = EventOrTransactionId.EventId(pollStartId.value),
)
}.map { }
}

Expand All @@ -482,7 +485,7 @@ class RustTimeline(
): Result<Unit> = withContext(dispatcher) {
runCatching {
inner.sendPollResponse(
pollStartId = pollStartId.value,
pollStartEventId = pollStartId.value,
answers = answers,
)
}
Expand All @@ -494,7 +497,7 @@ class RustTimeline(
): Result<Unit> = withContext(dispatcher) {
runCatching {
inner.endPoll(
pollStartId = pollStartId.value,
pollStartEventId = pollStartId.value,
text = text,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ internal fun TimelineDiff.eventOrigin(): EventItemOrigin? {
}

private fun TimelineItem.eventOrigin(): EventItemOrigin? {
return asEvent()?.origin()
return asEvent()?.origin
}
Loading

0 comments on commit 3001efb

Please sign in to comment.