diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/messagecomposer/MessageComposerPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/messagecomposer/MessageComposerPresenter.kt index 6898d7796f..d6e74a0df0 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/messagecomposer/MessageComposerPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/messagecomposer/MessageComposerPresenter.kt @@ -154,12 +154,10 @@ class MessageComposerPresenter @Inject constructor( fun handleEvents(event: MessageComposerEvents) { when (event) { MessageComposerEvents.ToggleFullScreenState -> isFullScreen.value = !isFullScreen.value - MessageComposerEvents.CloseSpecialMode -> { richTextEditorState.setHtml("") messageComposerContext.composerMode = MessageComposerMode.Normal("") } - is MessageComposerEvents.SendMessage -> appCoroutineScope.sendMessage( message = event.message, updateComposerMode = { messageComposerContext.composerMode = it }, @@ -167,6 +165,11 @@ class MessageComposerPresenter @Inject constructor( ) is MessageComposerEvents.SetMode -> { messageComposerContext.composerMode = event.composerMode + if (event.composerMode is MessageComposerMode.Reply) { + appCoroutineScope.launch { + room.enterReplyMode(event.composerMode.eventId) + } + } } MessageComposerEvents.AddAttachment -> localCoroutineScope.launch { showAttachmentSourcePicker = true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5e25c9f360..9f8af860fb 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -150,7 +150,7 @@ jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" } appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" } molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule" } 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_compose = { module = "io.element.android:wysiwyg-compose", version.ref = "wysiwyg" } sqldelight-driver-android = { module = "com.squareup.sqldelight:android-driver", version.ref = "sqldelight" } diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notification/NotificationData.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notification/NotificationData.kt index 8565e4c747..290a54c502 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notification/NotificationData.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notification/NotificationData.kt @@ -61,6 +61,7 @@ sealed interface NotificationContent { ) : MessageLike data object RoomRedaction : MessageLike data object Sticker : MessageLike + data class Poll(val question: String) : MessageLike } sealed interface StateEvent : NotificationContent { diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt index 1dd6101354..17cb637d80 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt @@ -89,6 +89,8 @@ interface MatrixRoom : Closeable { suspend fun editMessage(originalEventId: EventId?, transactionId: TransactionId?, body: String, htmlBody: String?): Result + suspend fun enterReplyMode(eventId: EventId): Result + suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result suspend fun redactEvent(eventId: EventId, reason: String? = null): Result @@ -184,7 +186,4 @@ interface MatrixRoom : Closeable { suspend fun endPoll(pollStartId: EventId, text: String): Result override fun close() = destroy() - } - - diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/notification/TimelineEventToNotificationContentMapper.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/notification/TimelineEventToNotificationContentMapper.kt index e30e57113d..b82716cc2d 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/notification/TimelineEventToNotificationContentMapper.kt +++ b/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.Sticker -> NotificationContent.MessageLike.Sticker + is MessageLikeEventContent.Poll -> NotificationContent.MessageLike.Poll(question) } } } diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RoomContentForwarder.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RoomContentForwarder.kt index 8ee0361ace..d539ec6a53 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RoomContentForwarder.kt +++ b/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.TimelineDiff import org.matrix.rustcomponents.sdk.TimelineListener -import org.matrix.rustcomponents.sdk.genTransactionId import kotlin.time.Duration.Companion.milliseconds /** @@ -61,7 +60,7 @@ class RoomContentForwarder( // Sending a message requires a registered timeline listener targetRoom.addTimelineListener(NoOpTimelineListener) withTimeout(timeoutMs.milliseconds) { - targetRoom.send(content, genTransactionId()) + targetRoom.send(content) } } // After sending, we remove the timeline diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt index 4a8a3f9bee..4c20dd4d0c 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt @@ -60,6 +60,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.withContext +import org.matrix.rustcomponents.sdk.EventTimelineItem import org.matrix.rustcomponents.sdk.RequiredState import org.matrix.rustcomponents.sdk.Room 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.RoomSubscription import org.matrix.rustcomponents.sdk.SendAttachmentJoinHandle -import org.matrix.rustcomponents.sdk.genTransactionId import org.matrix.rustcomponents.sdk.messageEventContentFromHtml import org.matrix.rustcomponents.sdk.messageEventContentFromMarkdown import timber.log.Timber @@ -139,6 +139,7 @@ class RustMatrixRoom( roomCoroutineScope.cancel() innerRoom.destroy() roomListItem.destroy() + inReplyToEventTimelineItem?.destroy() } override val name: String? @@ -241,10 +242,9 @@ class RustMatrixRoom( } override suspend fun sendMessage(body: String, htmlBody: String?): Result = withContext(roomDispatcher) { - val transactionId = genTransactionId() messageEventContentFromParts(body, htmlBody).use { content -> runCatching { - innerRoom.send(content, transactionId) + innerRoom.send(content) } } } @@ -253,26 +253,39 @@ class RustMatrixRoom( withContext(roomDispatcher) { if (originalEventId != null) { runCatching { - innerRoom.edit(messageEventContentFromParts(body, htmlBody), originalEventId.value, transactionId?.value) + innerRoom.edit(messageEventContentFromParts(body, htmlBody), originalEventId.value) } } else { runCatching { 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 = withContext(roomDispatcher) { + runCatching { + inReplyToEventTimelineItem?.destroy() + inReplyToEventTimelineItem = null + inReplyToEventTimelineItem = innerRoom.getEventTimelineItemByEventId(eventId.value) + } + } + override suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result = withContext(roomDispatcher) { 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) { - val transactionId = genTransactionId() runCatching { - innerRoom.redact(eventId.value, reason, transactionId) + innerRoom.redact(eventId.value, reason) } } @@ -416,7 +429,6 @@ class RustMatrixRoom( description = description, zoomLevel = zoomLevel?.toUByte(), assetType = assetType?.toInner(), - txnId = genTransactionId(), ) } } @@ -433,7 +445,6 @@ class RustMatrixRoom( answers = answers, maxSelections = maxSelections.toUByte(), pollKind = pollKind.toInner(), - txnId = genTransactionId(), ) } } @@ -446,7 +457,6 @@ class RustMatrixRoom( innerRoom.sendPollResponse( pollStartId = pollStartId.value, answers = answers, - txnId = genTransactionId(), ) } } @@ -459,7 +469,6 @@ class RustMatrixRoom( innerRoom.endPoll( pollStartId = pollStartId.value, text = text, - txnId = genTransactionId(), ) } } diff --git a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt index 0e8916e87e..e8abdb62df 100644 --- a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt +++ b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt @@ -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.room.MatrixRoom 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.MessageEventType 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.timeline.MatrixTimeline @@ -208,6 +208,10 @@ class FakeMatrixRoom( var replyMessageParameter: Pair? = null private set + override suspend fun enterReplyMode(eventId: EventId): Result { + return Result.success(Unit) + } + override suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result { replyMessageParameter = body to htmlBody return Result.success(Unit) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotifiableEventResolver.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotifiableEventResolver.kt index c93d517e89..9951698b88 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotifiableEventResolver.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotifiableEventResolver.kt @@ -114,10 +114,63 @@ class NotifiableEventResolver @Inject constructor( title = null, // TODO check if title is needed anymore ) } 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}") + } } }