diff --git a/CHANGES.md b/CHANGES.md index 92c5c56647..f5485f828e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Bugfix 🐛: - Long message cannot be sent/takes infinite time & blocks other messages #1397 - User Verification in DM not working - Manual import of Megolm keys does back up the imported keys + - Auto scrolling to the latest message when sending (#2094) - Fix incorrect permission check when creating widgets (#2137) Translations 🗣: diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimeline.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimeline.kt index 2dead1d9cc..3189b0702e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimeline.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimeline.kt @@ -29,6 +29,7 @@ import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode import org.matrix.android.sdk.api.MatrixCallback import org.matrix.android.sdk.api.extensions.orFalse +import org.matrix.android.sdk.api.extensions.tryThis import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.RelationType import org.matrix.android.sdk.api.session.events.model.toModel @@ -333,12 +334,22 @@ internal class DefaultTimeline( // Private methods ***************************************************************************** - private fun rebuildEvent(eventId: String, builder: (TimelineEvent) -> TimelineEvent): Boolean { - return builtEventsIdMap[eventId]?.let { builtIndex -> - // Update the relation of existing event - builtEvents[builtIndex]?.let { te -> - builtEvents[builtIndex] = builder(te) - true + private fun rebuildEvent(eventId: String, builder: (TimelineEvent) -> TimelineEvent?): Boolean { + return tryThis { + builtEventsIdMap[eventId]?.let { builtIndex -> + // Update the relation of existing event + builtEvents[builtIndex]?.let { te -> + val rebuiltEvent = builder(te) + // If rebuilt event is filtered its returned as null and should be removed. + if (rebuiltEvent == null) { + builtEventsIdMap.remove(eventId) + builtEventsIdMap.entries.filter { it.value > builtIndex }.forEach { it.setValue(it.value - 1) } + builtEvents.removeAt(builtIndex) + } else { + builtEvents[builtIndex] = rebuiltEvent + } + true + } } } ?: false } @@ -413,14 +424,14 @@ internal class DefaultTimeline( private fun getState(direction: Timeline.Direction): State { return when (direction) { - Timeline.Direction.FORWARDS -> forwardsState.get() + Timeline.Direction.FORWARDS -> forwardsState.get() Timeline.Direction.BACKWARDS -> backwardsState.get() } } private fun updateState(direction: Timeline.Direction, update: (State) -> State) { val stateReference = when (direction) { - Timeline.Direction.FORWARDS -> forwardsState + Timeline.Direction.FORWARDS -> forwardsState Timeline.Direction.BACKWARDS -> backwardsState } val currentValue = stateReference.get() @@ -489,7 +500,8 @@ internal class DefaultTimeline( val eventEntity = results[index] eventEntity?.eventId?.let { eventId -> postSnapshot = rebuildEvent(eventId) { - buildTimelineEvent(eventEntity) + val builtEvent = buildTimelineEvent(eventEntity) + listOf(builtEvent).filterEventsWithSettings().firstOrNull() } || postSnapshot } } @@ -730,10 +742,10 @@ internal class DefaultTimeline( return object : MatrixCallback { override fun onSuccess(data: TokenChunkEventPersistor.Result) { when (data) { - TokenChunkEventPersistor.Result.SUCCESS -> { + TokenChunkEventPersistor.Result.SUCCESS -> { Timber.v("Success fetching $limit items $direction from pagination request") } - TokenChunkEventPersistor.Result.REACHED_END -> { + TokenChunkEventPersistor.Result.REACHED_END -> { postSnapshot() } TokenChunkEventPersistor.Result.SHOULD_FETCH_MORE -> @@ -775,9 +787,8 @@ internal class DefaultTimeline( } if (!filterEdits) return@filter false - val filterRedacted = !settings.filters.filterRedacted || it.root.isRedacted() - - filterRedacted + val filterRedacted = settings.filters.filterRedacted && it.root.isRedacted() + !filterRedacted } }