Skip to content

Commit 971f8cf

Browse files
authored
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
2 parents 161c6d0 + c9c7af6 commit 971f8cf

File tree

9 files changed

+92
-23
lines changed

9 files changed

+92
-23
lines changed

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/messagecomposer/MessageComposerPresenter.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,22 @@ class MessageComposerPresenter @Inject constructor(
154154
fun handleEvents(event: MessageComposerEvents) {
155155
when (event) {
156156
MessageComposerEvents.ToggleFullScreenState -> isFullScreen.value = !isFullScreen.value
157-
158157
MessageComposerEvents.CloseSpecialMode -> {
159158
richTextEditorState.setHtml("")
160159
messageComposerContext.composerMode = MessageComposerMode.Normal("")
161160
}
162-
163161
is MessageComposerEvents.SendMessage -> appCoroutineScope.sendMessage(
164162
message = event.message,
165163
updateComposerMode = { messageComposerContext.composerMode = it },
166164
richTextEditorState = richTextEditorState,
167165
)
168166
is MessageComposerEvents.SetMode -> {
169167
messageComposerContext.composerMode = event.composerMode
168+
if (event.composerMode is MessageComposerMode.Reply) {
169+
appCoroutineScope.launch {
170+
room.enterReplyMode(event.composerMode.eventId)
171+
}
172+
}
170173
}
171174
MessageComposerEvents.AddAttachment -> localCoroutineScope.launch {
172175
showAttachmentSourcePicker = true

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" }
150150
appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" }
151151
molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule" }
152152
timber = "com.jakewharton.timber:timber:5.0.1"
153-
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.1.57"
153+
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.1.58"
154154
matrix_richtexteditor = { module = "io.element.android:wysiwyg", version.ref = "wysiwyg" }
155155
matrix_richtexteditor_compose = { module = "io.element.android:wysiwyg-compose", version.ref = "wysiwyg" }
156156
sqldelight-driver-android = { module = "com.squareup.sqldelight:android-driver", version.ref = "sqldelight" }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ sealed interface NotificationContent {
6161
) : MessageLike
6262
data object RoomRedaction : MessageLike
6363
data object Sticker : MessageLike
64+
data class Poll(val question: String) : MessageLike
6465
}
6566

6667
sealed interface StateEvent : NotificationContent {

libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ interface MatrixRoom : Closeable {
8989

9090
suspend fun editMessage(originalEventId: EventId?, transactionId: TransactionId?, body: String, htmlBody: String?): Result<Unit>
9191

92+
suspend fun enterReplyMode(eventId: EventId): Result<Unit>
93+
9294
suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit>
9395

9496
suspend fun redactEvent(eventId: EventId, reason: String? = null): Result<Unit>
@@ -184,7 +186,4 @@ interface MatrixRoom : Closeable {
184186
suspend fun endPoll(pollStartId: EventId, text: String): Result<Unit>
185187

186188
override fun close() = destroy()
187-
188189
}
189-
190-

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ private fun MessageLikeEventContent.toContent(senderId: UserId): NotificationCon
9494
}
9595
MessageLikeEventContent.RoomRedaction -> NotificationContent.MessageLike.RoomRedaction
9696
MessageLikeEventContent.Sticker -> NotificationContent.MessageLike.Sticker
97+
is MessageLikeEventContent.Poll -> NotificationContent.MessageLike.Poll(question)
9798
}
9899
}
99100
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import org.matrix.rustcomponents.sdk.Room
2727
import org.matrix.rustcomponents.sdk.RoomListService
2828
import org.matrix.rustcomponents.sdk.TimelineDiff
2929
import org.matrix.rustcomponents.sdk.TimelineListener
30-
import org.matrix.rustcomponents.sdk.genTransactionId
3130
import kotlin.time.Duration.Companion.milliseconds
3231

3332
/**
@@ -61,7 +60,7 @@ class RoomContentForwarder(
6160
// Sending a message requires a registered timeline listener
6261
targetRoom.addTimelineListener(NoOpTimelineListener)
6362
withTimeout(timeoutMs.milliseconds) {
64-
targetRoom.send(content, genTransactionId())
63+
targetRoom.send(content)
6564
}
6665
}
6766
// After sending, we remove the timeline

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ import kotlinx.coroutines.flow.MutableStateFlow
6060
import kotlinx.coroutines.flow.StateFlow
6161
import kotlinx.coroutines.flow.asStateFlow
6262
import kotlinx.coroutines.withContext
63+
import org.matrix.rustcomponents.sdk.EventTimelineItem
6364
import org.matrix.rustcomponents.sdk.RequiredState
6465
import org.matrix.rustcomponents.sdk.Room
6566
import org.matrix.rustcomponents.sdk.RoomListItem
6667
import org.matrix.rustcomponents.sdk.RoomMember
6768
import org.matrix.rustcomponents.sdk.RoomMessageEventContentWithoutRelation
6869
import org.matrix.rustcomponents.sdk.RoomSubscription
6970
import org.matrix.rustcomponents.sdk.SendAttachmentJoinHandle
70-
import org.matrix.rustcomponents.sdk.genTransactionId
7171
import org.matrix.rustcomponents.sdk.messageEventContentFromHtml
7272
import org.matrix.rustcomponents.sdk.messageEventContentFromMarkdown
7373
import timber.log.Timber
@@ -139,6 +139,7 @@ class RustMatrixRoom(
139139
roomCoroutineScope.cancel()
140140
innerRoom.destroy()
141141
roomListItem.destroy()
142+
inReplyToEventTimelineItem?.destroy()
142143
}
143144

144145
override val name: String?
@@ -241,10 +242,9 @@ class RustMatrixRoom(
241242
}
242243

243244
override suspend fun sendMessage(body: String, htmlBody: String?): Result<Unit> = withContext(roomDispatcher) {
244-
val transactionId = genTransactionId()
245245
messageEventContentFromParts(body, htmlBody).use { content ->
246246
runCatching {
247-
innerRoom.send(content, transactionId)
247+
innerRoom.send(content)
248248
}
249249
}
250250
}
@@ -253,26 +253,39 @@ class RustMatrixRoom(
253253
withContext(roomDispatcher) {
254254
if (originalEventId != null) {
255255
runCatching {
256-
innerRoom.edit(messageEventContentFromParts(body, htmlBody), originalEventId.value, transactionId?.value)
256+
innerRoom.edit(messageEventContentFromParts(body, htmlBody), originalEventId.value)
257257
}
258258
} else {
259259
runCatching {
260260
transactionId?.let { cancelSend(it) }
261-
innerRoom.send(messageEventContentFromParts(body, htmlBody), genTransactionId())
261+
innerRoom.send(messageEventContentFromParts(body, htmlBody))
262262
}
263263
}
264264
}
265265

266+
private var inReplyToEventTimelineItem: EventTimelineItem? = null
267+
268+
override suspend fun enterReplyMode(eventId: EventId): Result<Unit> = withContext(roomDispatcher) {
269+
runCatching {
270+
inReplyToEventTimelineItem?.destroy()
271+
inReplyToEventTimelineItem = null
272+
inReplyToEventTimelineItem = innerRoom.getEventTimelineItemByEventId(eventId.value)
273+
}
274+
}
275+
266276
override suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit> = withContext(roomDispatcher) {
267277
runCatching {
268-
innerRoom.sendReply(messageEventContentFromParts(body, htmlBody), eventId.value, genTransactionId())
278+
val inReplyTo = inReplyToEventTimelineItem ?: innerRoom.getEventTimelineItemByEventId(eventId.value)
279+
inReplyTo.use { eventTimelineItem ->
280+
innerRoom.sendReply(messageEventContentFromParts(body, htmlBody), eventTimelineItem)
281+
}
282+
inReplyToEventTimelineItem = null
269283
}
270284
}
271285

272286
override suspend fun redactEvent(eventId: EventId, reason: String?) = withContext(roomDispatcher) {
273-
val transactionId = genTransactionId()
274287
runCatching {
275-
innerRoom.redact(eventId.value, reason, transactionId)
288+
innerRoom.redact(eventId.value, reason)
276289
}
277290
}
278291

@@ -416,7 +429,6 @@ class RustMatrixRoom(
416429
description = description,
417430
zoomLevel = zoomLevel?.toUByte(),
418431
assetType = assetType?.toInner(),
419-
txnId = genTransactionId(),
420432
)
421433
}
422434
}
@@ -433,7 +445,6 @@ class RustMatrixRoom(
433445
answers = answers,
434446
maxSelections = maxSelections.toUByte(),
435447
pollKind = pollKind.toInner(),
436-
txnId = genTransactionId(),
437448
)
438449
}
439450
}
@@ -446,7 +457,6 @@ class RustMatrixRoom(
446457
innerRoom.sendPollResponse(
447458
pollStartId = pollStartId.value,
448459
answers = answers,
449-
txnId = genTransactionId(),
450460
)
451461
}
452462
}
@@ -459,7 +469,6 @@ class RustMatrixRoom(
459469
innerRoom.endPoll(
460470
pollStartId = pollStartId.value,
461471
text = text,
462-
txnId = genTransactionId(),
463472
)
464473
}
465474
}

libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import io.element.android.libraries.matrix.api.notificationsettings.Notification
3131
import io.element.android.libraries.matrix.api.poll.PollKind
3232
import io.element.android.libraries.matrix.api.room.MatrixRoom
3333
import io.element.android.libraries.matrix.api.room.MatrixRoomMembersState
34-
import io.element.android.libraries.matrix.api.room.MessageEventType
3534
import io.element.android.libraries.matrix.api.room.MatrixRoomNotificationSettingsState
35+
import io.element.android.libraries.matrix.api.room.MessageEventType
3636
import io.element.android.libraries.matrix.api.room.StateEventType
3737
import io.element.android.libraries.matrix.api.room.location.AssetType
3838
import io.element.android.libraries.matrix.api.timeline.MatrixTimeline
@@ -208,6 +208,10 @@ class FakeMatrixRoom(
208208
var replyMessageParameter: Pair<String, String?>? = null
209209
private set
210210

211+
override suspend fun enterReplyMode(eventId: EventId): Result<Unit> {
212+
return Result.success(Unit)
213+
}
214+
211215
override suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit> {
212216
replyMessageParameter = body to htmlBody
213217
return Result.success(Unit)

libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotifiableEventResolver.kt

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,63 @@ class NotifiableEventResolver @Inject constructor(
114114
title = null, // TODO check if title is needed anymore
115115
)
116116
} else {
117-
fallbackNotifiableEvent(userId, roomId, eventId)
117+
Timber.tag(loggerTag.value).d("Ignoring notification state event for membership ${content.membershipState}")
118+
null
118119
}
119120
}
120-
else -> fallbackNotifiableEvent(userId, roomId, eventId)
121+
NotificationContent.MessageLike.CallAnswer,
122+
NotificationContent.MessageLike.CallCandidates,
123+
NotificationContent.MessageLike.CallHangup,
124+
NotificationContent.MessageLike.CallInvite -> null.also {
125+
Timber.tag(loggerTag.value).d("Ignoring notification for call ${content.javaClass.simpleName}")
126+
}
127+
NotificationContent.MessageLike.KeyVerificationAccept,
128+
NotificationContent.MessageLike.KeyVerificationCancel,
129+
NotificationContent.MessageLike.KeyVerificationDone,
130+
NotificationContent.MessageLike.KeyVerificationKey,
131+
NotificationContent.MessageLike.KeyVerificationMac,
132+
NotificationContent.MessageLike.KeyVerificationReady,
133+
NotificationContent.MessageLike.KeyVerificationStart -> null.also {
134+
Timber.tag(loggerTag.value).d("Ignoring notification for verification ${content.javaClass.simpleName}")
135+
}
136+
is NotificationContent.MessageLike.Poll -> null.also {
137+
// TODO Polls: handle notification rendering
138+
Timber.tag(loggerTag.value).d("Ignoring notification for poll")
139+
}
140+
is NotificationContent.MessageLike.ReactionContent -> null.also {
141+
Timber.tag(loggerTag.value).d("Ignoring notification for reaction")
142+
}
143+
NotificationContent.MessageLike.RoomEncrypted -> fallbackNotifiableEvent(userId, roomId, eventId).also {
144+
Timber.tag(loggerTag.value).w("Notification with encrypted content -> fallback")
145+
}
146+
NotificationContent.MessageLike.RoomRedaction -> null.also {
147+
Timber.tag(loggerTag.value).d("Ignoring notification for redaction")
148+
}
149+
NotificationContent.MessageLike.Sticker -> null.also {
150+
Timber.tag(loggerTag.value).d("Ignoring notification for sticker")
151+
}
152+
NotificationContent.StateEvent.PolicyRuleRoom,
153+
NotificationContent.StateEvent.PolicyRuleServer,
154+
NotificationContent.StateEvent.PolicyRuleUser,
155+
NotificationContent.StateEvent.RoomAliases,
156+
NotificationContent.StateEvent.RoomAvatar,
157+
NotificationContent.StateEvent.RoomCanonicalAlias,
158+
NotificationContent.StateEvent.RoomCreate,
159+
NotificationContent.StateEvent.RoomEncryption,
160+
NotificationContent.StateEvent.RoomGuestAccess,
161+
NotificationContent.StateEvent.RoomHistoryVisibility,
162+
NotificationContent.StateEvent.RoomJoinRules,
163+
NotificationContent.StateEvent.RoomName,
164+
NotificationContent.StateEvent.RoomPinnedEvents,
165+
NotificationContent.StateEvent.RoomPowerLevels,
166+
NotificationContent.StateEvent.RoomServerAcl,
167+
NotificationContent.StateEvent.RoomThirdPartyInvite,
168+
NotificationContent.StateEvent.RoomTombstone,
169+
NotificationContent.StateEvent.RoomTopic,
170+
NotificationContent.StateEvent.SpaceChild,
171+
NotificationContent.StateEvent.SpaceParent -> null.also {
172+
Timber.tag(loggerTag.value).d("Ignoring notification for state event ${content.javaClass.simpleName}")
173+
}
121174
}
122175
}
123176

0 commit comments

Comments
 (0)