Merge pull request #1437 from vector-im/renovate/org.matrix.rustcomponents-sdk-android-0.x

Update dependency org.matrix.rustcomponents:sdk-android to v0.1.58
This commit is contained in:
Benoit Marty 2023-09-27 11:53:17 +02:00 committed by GitHub
commit 9514aed890
9 changed files with 92 additions and 23 deletions

View file

@ -154,12 +154,10 @@ class MessageComposerPresenter @Inject constructor(
fun handleEvents(event: MessageComposerEvents) { fun handleEvents(event: MessageComposerEvents) {
when (event) { when (event) {
MessageComposerEvents.ToggleFullScreenState -> isFullScreen.value = !isFullScreen.value MessageComposerEvents.ToggleFullScreenState -> isFullScreen.value = !isFullScreen.value
MessageComposerEvents.CloseSpecialMode -> { MessageComposerEvents.CloseSpecialMode -> {
richTextEditorState.setHtml("") richTextEditorState.setHtml("")
messageComposerContext.composerMode = MessageComposerMode.Normal("") messageComposerContext.composerMode = MessageComposerMode.Normal("")
} }
is MessageComposerEvents.SendMessage -> appCoroutineScope.sendMessage( is MessageComposerEvents.SendMessage -> appCoroutineScope.sendMessage(
message = event.message, message = event.message,
updateComposerMode = { messageComposerContext.composerMode = it }, updateComposerMode = { messageComposerContext.composerMode = it },
@ -167,6 +165,11 @@ class MessageComposerPresenter @Inject constructor(
) )
is MessageComposerEvents.SetMode -> { is MessageComposerEvents.SetMode -> {
messageComposerContext.composerMode = event.composerMode messageComposerContext.composerMode = event.composerMode
if (event.composerMode is MessageComposerMode.Reply) {
appCoroutineScope.launch {
room.enterReplyMode(event.composerMode.eventId)
}
}
} }
MessageComposerEvents.AddAttachment -> localCoroutineScope.launch { MessageComposerEvents.AddAttachment -> localCoroutineScope.launch {
showAttachmentSourcePicker = true showAttachmentSourcePicker = true

View file

@ -150,7 +150,7 @@ jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" }
appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" } appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" }
molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule" } molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule" }
timber = "com.jakewharton.timber:timber:5.0.1" timber = "com.jakewharton.timber:timber:5.0.1"
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.1.57" matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.1.58"
matrix_richtexteditor = { module = "io.element.android:wysiwyg", version.ref = "wysiwyg" } matrix_richtexteditor = { module = "io.element.android:wysiwyg", version.ref = "wysiwyg" }
matrix_richtexteditor_compose = { module = "io.element.android:wysiwyg-compose", version.ref = "wysiwyg" } matrix_richtexteditor_compose = { module = "io.element.android:wysiwyg-compose", version.ref = "wysiwyg" }
sqldelight-driver-android = { module = "com.squareup.sqldelight:android-driver", version.ref = "sqldelight" } sqldelight-driver-android = { module = "com.squareup.sqldelight:android-driver", version.ref = "sqldelight" }

View file

@ -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 {

View file

@ -89,6 +89,8 @@ interface MatrixRoom : Closeable {
suspend fun editMessage(originalEventId: EventId?, transactionId: TransactionId?, body: String, htmlBody: String?): Result<Unit> suspend fun editMessage(originalEventId: EventId?, transactionId: TransactionId?, body: String, htmlBody: String?): Result<Unit>
suspend fun enterReplyMode(eventId: EventId): Result<Unit>
suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit> suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit>
suspend fun redactEvent(eventId: EventId, reason: String? = null): Result<Unit> suspend fun redactEvent(eventId: EventId, reason: String? = null): Result<Unit>
@ -184,7 +186,4 @@ interface MatrixRoom : Closeable {
suspend fun endPoll(pollStartId: EventId, text: String): Result<Unit> suspend fun endPoll(pollStartId: EventId, text: String): Result<Unit>
override fun close() = destroy() override fun close() = destroy()
} }

View file

@ -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)
} }
} }
} }

View file

@ -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

View file

@ -60,6 +60,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.matrix.rustcomponents.sdk.EventTimelineItem
import org.matrix.rustcomponents.sdk.RequiredState import org.matrix.rustcomponents.sdk.RequiredState
import org.matrix.rustcomponents.sdk.Room import org.matrix.rustcomponents.sdk.Room
import org.matrix.rustcomponents.sdk.RoomListItem import org.matrix.rustcomponents.sdk.RoomListItem
@ -67,7 +68,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
@ -139,6 +139,7 @@ class RustMatrixRoom(
roomCoroutineScope.cancel() roomCoroutineScope.cancel()
innerRoom.destroy() innerRoom.destroy()
roomListItem.destroy() roomListItem.destroy()
inReplyToEventTimelineItem?.destroy()
} }
override val name: String? override val name: String?
@ -241,10 +242,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 +253,39 @@ 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))
} }
} }
} }
private var inReplyToEventTimelineItem: EventTimelineItem? = null
override suspend fun enterReplyMode(eventId: EventId): Result<Unit> = withContext(roomDispatcher) {
runCatching {
inReplyToEventTimelineItem?.destroy()
inReplyToEventTimelineItem = null
inReplyToEventTimelineItem = innerRoom.getEventTimelineItemByEventId(eventId.value)
}
}
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()) val inReplyTo = inReplyToEventTimelineItem ?: innerRoom.getEventTimelineItemByEventId(eventId.value)
inReplyTo.use { eventTimelineItem ->
innerRoom.sendReply(messageEventContentFromParts(body, htmlBody), eventTimelineItem)
}
inReplyToEventTimelineItem = null
} }
} }
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 +429,6 @@ class RustMatrixRoom(
description = description, description = description,
zoomLevel = zoomLevel?.toUByte(), zoomLevel = zoomLevel?.toUByte(),
assetType = assetType?.toInner(), assetType = assetType?.toInner(),
txnId = genTransactionId(),
) )
} }
} }
@ -433,7 +445,6 @@ class RustMatrixRoom(
answers = answers, answers = answers,
maxSelections = maxSelections.toUByte(), maxSelections = maxSelections.toUByte(),
pollKind = pollKind.toInner(), pollKind = pollKind.toInner(),
txnId = genTransactionId(),
) )
} }
} }
@ -446,7 +457,6 @@ class RustMatrixRoom(
innerRoom.sendPollResponse( innerRoom.sendPollResponse(
pollStartId = pollStartId.value, pollStartId = pollStartId.value,
answers = answers, answers = answers,
txnId = genTransactionId(),
) )
} }
} }
@ -459,7 +469,6 @@ class RustMatrixRoom(
innerRoom.endPoll( innerRoom.endPoll(
pollStartId = pollStartId.value, pollStartId = pollStartId.value,
text = text, text = text,
txnId = genTransactionId(),
) )
} }
} }

View file

@ -31,8 +31,8 @@ import io.element.android.libraries.matrix.api.notificationsettings.Notification
import io.element.android.libraries.matrix.api.poll.PollKind import io.element.android.libraries.matrix.api.poll.PollKind
import io.element.android.libraries.matrix.api.room.MatrixRoom import io.element.android.libraries.matrix.api.room.MatrixRoom
import io.element.android.libraries.matrix.api.room.MatrixRoomMembersState import io.element.android.libraries.matrix.api.room.MatrixRoomMembersState
import io.element.android.libraries.matrix.api.room.MessageEventType
import io.element.android.libraries.matrix.api.room.MatrixRoomNotificationSettingsState import io.element.android.libraries.matrix.api.room.MatrixRoomNotificationSettingsState
import io.element.android.libraries.matrix.api.room.MessageEventType
import io.element.android.libraries.matrix.api.room.StateEventType import io.element.android.libraries.matrix.api.room.StateEventType
import io.element.android.libraries.matrix.api.room.location.AssetType import io.element.android.libraries.matrix.api.room.location.AssetType
import io.element.android.libraries.matrix.api.timeline.MatrixTimeline import io.element.android.libraries.matrix.api.timeline.MatrixTimeline
@ -208,6 +208,10 @@ class FakeMatrixRoom(
var replyMessageParameter: Pair<String, String?>? = null var replyMessageParameter: Pair<String, String?>? = null
private set private set
override suspend fun enterReplyMode(eventId: EventId): Result<Unit> {
return Result.success(Unit)
}
override suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit> { override suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit> {
replyMessageParameter = body to htmlBody replyMessageParameter = body to htmlBody
return Result.success(Unit) return Result.success(Unit)

View file

@ -114,10 +114,63 @@ class NotifiableEventResolver @Inject constructor(
title = null, // TODO check if title is needed anymore title = null, // TODO check if title is needed anymore
) )
} else { } else {
fallbackNotifiableEvent(userId, roomId, eventId) Timber.tag(loggerTag.value).d("Ignoring notification state event for membership ${content.membershipState}")
null
} }
} }
else -> fallbackNotifiableEvent(userId, roomId, eventId) NotificationContent.MessageLike.CallAnswer,
NotificationContent.MessageLike.CallCandidates,
NotificationContent.MessageLike.CallHangup,
NotificationContent.MessageLike.CallInvite -> null.also {
Timber.tag(loggerTag.value).d("Ignoring notification for call ${content.javaClass.simpleName}")
}
NotificationContent.MessageLike.KeyVerificationAccept,
NotificationContent.MessageLike.KeyVerificationCancel,
NotificationContent.MessageLike.KeyVerificationDone,
NotificationContent.MessageLike.KeyVerificationKey,
NotificationContent.MessageLike.KeyVerificationMac,
NotificationContent.MessageLike.KeyVerificationReady,
NotificationContent.MessageLike.KeyVerificationStart -> null.also {
Timber.tag(loggerTag.value).d("Ignoring notification for verification ${content.javaClass.simpleName}")
}
is NotificationContent.MessageLike.Poll -> null.also {
// TODO Polls: handle notification rendering
Timber.tag(loggerTag.value).d("Ignoring notification for poll")
}
is NotificationContent.MessageLike.ReactionContent -> null.also {
Timber.tag(loggerTag.value).d("Ignoring notification for reaction")
}
NotificationContent.MessageLike.RoomEncrypted -> fallbackNotifiableEvent(userId, roomId, eventId).also {
Timber.tag(loggerTag.value).w("Notification with encrypted content -> fallback")
}
NotificationContent.MessageLike.RoomRedaction -> null.also {
Timber.tag(loggerTag.value).d("Ignoring notification for redaction")
}
NotificationContent.MessageLike.Sticker -> null.also {
Timber.tag(loggerTag.value).d("Ignoring notification for sticker")
}
NotificationContent.StateEvent.PolicyRuleRoom,
NotificationContent.StateEvent.PolicyRuleServer,
NotificationContent.StateEvent.PolicyRuleUser,
NotificationContent.StateEvent.RoomAliases,
NotificationContent.StateEvent.RoomAvatar,
NotificationContent.StateEvent.RoomCanonicalAlias,
NotificationContent.StateEvent.RoomCreate,
NotificationContent.StateEvent.RoomEncryption,
NotificationContent.StateEvent.RoomGuestAccess,
NotificationContent.StateEvent.RoomHistoryVisibility,
NotificationContent.StateEvent.RoomJoinRules,
NotificationContent.StateEvent.RoomName,
NotificationContent.StateEvent.RoomPinnedEvents,
NotificationContent.StateEvent.RoomPowerLevels,
NotificationContent.StateEvent.RoomServerAcl,
NotificationContent.StateEvent.RoomThirdPartyInvite,
NotificationContent.StateEvent.RoomTombstone,
NotificationContent.StateEvent.RoomTopic,
NotificationContent.StateEvent.SpaceChild,
NotificationContent.StateEvent.SpaceParent -> null.also {
Timber.tag(loggerTag.value).d("Ignoring notification for state event ${content.javaClass.simpleName}")
}
} }
} }