Browse Source

Fix API break with Matrix SDK 0.1.58.

pull/1437/head
Benoit Marty 12 months ago
parent
commit
cf657df5fd
  1. 1
      libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notification/NotificationData.kt
  2. 1
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/notification/TimelineEventToNotificationContentMapper.kt
  3. 3
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RoomContentForwarder.kt
  4. 19
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt

1
libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notification/NotificationData.kt

@ -61,6 +61,7 @@ sealed interface NotificationContent {
) : MessageLike ) : MessageLike
data object RoomRedaction : MessageLike data object RoomRedaction : MessageLike
data object Sticker : MessageLike data object Sticker : MessageLike
data class Poll(val question: String) : MessageLike
} }
sealed interface StateEvent : NotificationContent { sealed interface StateEvent : NotificationContent {

1
libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/notification/TimelineEventToNotificationContentMapper.kt

@ -94,6 +94,7 @@ private fun MessageLikeEventContent.toContent(senderId: UserId): NotificationCon
} }
MessageLikeEventContent.RoomRedaction -> NotificationContent.MessageLike.RoomRedaction MessageLikeEventContent.RoomRedaction -> NotificationContent.MessageLike.RoomRedaction
MessageLikeEventContent.Sticker -> NotificationContent.MessageLike.Sticker MessageLikeEventContent.Sticker -> NotificationContent.MessageLike.Sticker
is MessageLikeEventContent.Poll -> NotificationContent.MessageLike.Poll(question)
} }
} }
} }

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

@ -27,7 +27,6 @@ import org.matrix.rustcomponents.sdk.Room
import org.matrix.rustcomponents.sdk.RoomListService import org.matrix.rustcomponents.sdk.RoomListService
import org.matrix.rustcomponents.sdk.TimelineDiff import org.matrix.rustcomponents.sdk.TimelineDiff
import org.matrix.rustcomponents.sdk.TimelineListener import org.matrix.rustcomponents.sdk.TimelineListener
import org.matrix.rustcomponents.sdk.genTransactionId
import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.milliseconds
/** /**
@ -61,7 +60,7 @@ class RoomContentForwarder(
// Sending a message requires a registered timeline listener // Sending a message requires a registered timeline listener
targetRoom.addTimelineListener(NoOpTimelineListener) targetRoom.addTimelineListener(NoOpTimelineListener)
withTimeout(timeoutMs.milliseconds) { withTimeout(timeoutMs.milliseconds) {
targetRoom.send(content, genTransactionId()) targetRoom.send(content)
} }
} }
// After sending, we remove the timeline // After sending, we remove the timeline

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

@ -67,7 +67,6 @@ import org.matrix.rustcomponents.sdk.RoomMember
import org.matrix.rustcomponents.sdk.RoomMessageEventContentWithoutRelation import org.matrix.rustcomponents.sdk.RoomMessageEventContentWithoutRelation
import org.matrix.rustcomponents.sdk.RoomSubscription import org.matrix.rustcomponents.sdk.RoomSubscription
import org.matrix.rustcomponents.sdk.SendAttachmentJoinHandle import org.matrix.rustcomponents.sdk.SendAttachmentJoinHandle
import org.matrix.rustcomponents.sdk.genTransactionId
import org.matrix.rustcomponents.sdk.messageEventContentFromHtml import org.matrix.rustcomponents.sdk.messageEventContentFromHtml
import org.matrix.rustcomponents.sdk.messageEventContentFromMarkdown import org.matrix.rustcomponents.sdk.messageEventContentFromMarkdown
import timber.log.Timber import timber.log.Timber
@ -241,10 +240,9 @@ class RustMatrixRoom(
} }
override suspend fun sendMessage(body: String, htmlBody: String?): Result<Unit> = withContext(roomDispatcher) { override suspend fun sendMessage(body: String, htmlBody: String?): Result<Unit> = withContext(roomDispatcher) {
val transactionId = genTransactionId()
messageEventContentFromParts(body, htmlBody).use { content -> messageEventContentFromParts(body, htmlBody).use { content ->
runCatching { runCatching {
innerRoom.send(content, transactionId) innerRoom.send(content)
} }
} }
} }
@ -253,26 +251,27 @@ class RustMatrixRoom(
withContext(roomDispatcher) { withContext(roomDispatcher) {
if (originalEventId != null) { if (originalEventId != null) {
runCatching { runCatching {
innerRoom.edit(messageEventContentFromParts(body, htmlBody), originalEventId.value, transactionId?.value) innerRoom.edit(messageEventContentFromParts(body, htmlBody), originalEventId.value)
} }
} else { } else {
runCatching { runCatching {
transactionId?.let { cancelSend(it) } transactionId?.let { cancelSend(it) }
innerRoom.send(messageEventContentFromParts(body, htmlBody), genTransactionId()) innerRoom.send(messageEventContentFromParts(body, htmlBody))
} }
} }
} }
override suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit> = withContext(roomDispatcher) { override suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit> = withContext(roomDispatcher) {
runCatching { runCatching {
innerRoom.sendReply(messageEventContentFromParts(body, htmlBody), eventId.value, genTransactionId()) innerRoom.getEventTimelineItemByEventId(eventId.value).use { eventTimelineItem ->
innerRoom.sendReply(messageEventContentFromParts(body, htmlBody), eventTimelineItem)
}
} }
} }
override suspend fun redactEvent(eventId: EventId, reason: String?) = withContext(roomDispatcher) { override suspend fun redactEvent(eventId: EventId, reason: String?) = withContext(roomDispatcher) {
val transactionId = genTransactionId()
runCatching { runCatching {
innerRoom.redact(eventId.value, reason, transactionId) innerRoom.redact(eventId.value, reason)
} }
} }
@ -416,7 +415,6 @@ class RustMatrixRoom(
description = description, description = description,
zoomLevel = zoomLevel?.toUByte(), zoomLevel = zoomLevel?.toUByte(),
assetType = assetType?.toInner(), assetType = assetType?.toInner(),
txnId = genTransactionId(),
) )
} }
} }
@ -433,7 +431,6 @@ class RustMatrixRoom(
answers = answers, answers = answers,
maxSelections = maxSelections.toUByte(), maxSelections = maxSelections.toUByte(),
pollKind = pollKind.toInner(), pollKind = pollKind.toInner(),
txnId = genTransactionId(),
) )
} }
} }
@ -446,7 +443,6 @@ class RustMatrixRoom(
innerRoom.sendPollResponse( innerRoom.sendPollResponse(
pollStartId = pollStartId.value, pollStartId = pollStartId.value,
answers = answers, answers = answers,
txnId = genTransactionId(),
) )
} }
} }
@ -459,7 +455,6 @@ class RustMatrixRoom(
innerRoom.endPoll( innerRoom.endPoll(
pollStartId = pollStartId.value, pollStartId = pollStartId.value,
text = text, text = text,
txnId = genTransactionId(),
) )
} }
} }

Loading…
Cancel
Save