Hide verbose state events from the timeline (#2225)

This commit is contained in:
Jorge Martin Espinosa 2024-01-12 22:23:52 +01:00 committed by GitHub
parent 0b859209e2
commit 4a7b04524a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 157 additions and 4 deletions

View file

@ -27,6 +27,7 @@ import io.element.android.libraries.matrix.impl.timeline.item.event.EventMessage
import io.element.android.libraries.matrix.impl.timeline.item.event.EventTimelineItemMapper
import io.element.android.libraries.matrix.impl.timeline.item.event.TimelineEventContentMapper
import io.element.android.libraries.matrix.impl.timeline.item.virtual.VirtualTimelineItemMapper
import io.element.android.libraries.matrix.impl.timeline.postprocessor.FilterHiddenStateEventsProcessor
import io.element.android.libraries.matrix.impl.timeline.postprocessor.TimelineEncryptedHistoryPostProcessor
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineDispatcher
@ -82,6 +83,8 @@ class RustMatrixTimeline(
dispatcher = dispatcher,
)
private val filterHiddenStateEventsProcessor = FilterHiddenStateEventsProcessor()
private val timelineItemFactory = MatrixTimelineItemMapper(
fetchDetailsForEvent = this::fetchDetailsForEvent,
roomCoroutineScope = roomCoroutineScope,
@ -101,9 +104,9 @@ class RustMatrixTimeline(
override val paginationState: StateFlow<MatrixTimeline.PaginationState> = _paginationState.asStateFlow()
@OptIn(ExperimentalCoroutinesApi::class)
override val timelineItems: Flow<List<MatrixTimelineItem>> = _timelineItems.mapLatest { items ->
encryptedHistoryPostProcessor.process(items)
}
override val timelineItems: Flow<List<MatrixTimelineItem>> = _timelineItems
.mapLatest { items -> encryptedHistoryPostProcessor.process(items) }
.mapLatest { items -> filterHiddenStateEventsProcessor.process(items) }
init {
Timber.d("Initialize timeline for room ${matrixRoom.roomId}")

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.matrix.impl.timeline.postprocessor
import io.element.android.libraries.matrix.api.timeline.MatrixTimelineItem
import io.element.android.libraries.matrix.api.timeline.item.event.StateContent
/**
* This class is used to filter out 'hidden' state events from the timeline.
*/
class FilterHiddenStateEventsProcessor {
fun process(items: List<MatrixTimelineItem>): List<MatrixTimelineItem> {
return items.filter { item ->
when (item) {
is MatrixTimelineItem.Event -> {
when (val content = item.event.content) {
// If it's a state event, make sure it's visible
is StateContent -> content.isVisibleInTimeline()
// We can display any other event
else -> true
}
}
is MatrixTimelineItem.Virtual -> true
is MatrixTimelineItem.Other -> true
}
}
}
}