Merge pull request #8841 from element-hq/feature/fga/fix_redacted_collapse

Fix redacted events not grouped correctly
This commit is contained in:
ganfra 2024-06-03 11:53:44 +02:00 committed by GitHub
commit 15a252b525
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 12 deletions

1
changelog.d/8840.bugfix Normal file
View file

@ -0,0 +1 @@
Fix redacted events not grouped correctly when hidden events are inserted between.

View file

@ -84,7 +84,7 @@ class MergedHeaderItemFactory @Inject constructor(
buildRoomCreationMergedSummary(currentPosition, items, partialState, event, eventIdToHighlight, requestModelBuild, callback) buildRoomCreationMergedSummary(currentPosition, items, partialState, event, eventIdToHighlight, requestModelBuild, callback)
isStartOfSameTypeEventsSummary(event, nextEvent, addDaySeparator) -> isStartOfSameTypeEventsSummary(event, nextEvent, addDaySeparator) ->
buildSameTypeEventsMergedSummary(currentPosition, items, partialState, event, eventIdToHighlight, requestModelBuild, callback) buildSameTypeEventsMergedSummary(currentPosition, items, partialState, event, eventIdToHighlight, requestModelBuild, callback)
isStartOfRedactedEventsSummary(event, items, currentPosition, addDaySeparator) -> isStartOfRedactedEventsSummary(event, items, currentPosition, partialState, addDaySeparator) ->
buildRedactedEventsMergedSummary(currentPosition, items, partialState, event, eventIdToHighlight, requestModelBuild, callback) buildRedactedEventsMergedSummary(currentPosition, items, partialState, event, eventIdToHighlight, requestModelBuild, callback)
else -> null else -> null
} }
@ -122,19 +122,25 @@ class MergedHeaderItemFactory @Inject constructor(
* @param event the main timeline event * @param event the main timeline event
* @param items all known items, sorted from newer event to oldest event * @param items all known items, sorted from newer event to oldest event
* @param currentPosition the current position * @param currentPosition the current position
* @param partialState partial state data
* @param addDaySeparator true to add a day separator * @param addDaySeparator true to add a day separator
*/ */
private fun isStartOfRedactedEventsSummary( private fun isStartOfRedactedEventsSummary(
event: TimelineEvent, event: TimelineEvent,
items: List<TimelineEvent>, items: List<TimelineEvent>,
currentPosition: Int, currentPosition: Int,
partialState: TimelineEventController.PartialState,
addDaySeparator: Boolean, addDaySeparator: Boolean,
): Boolean { ): Boolean {
val nextNonRedactionEvent = items val nextDisplayableEvent = items.subList(currentPosition + 1, items.size).firstOrNull {
.subList(fromIndex = currentPosition + 1, toIndex = items.size) timelineEventVisibilityHelper.shouldShowEvent(
.find { it.root.getClearType() != EventType.REDACTION } timelineEvent = it,
return event.root.isRedacted() && highlightedEventId = partialState.highlightedEventId,
(!nextNonRedactionEvent?.root?.isRedacted().orFalse() || addDaySeparator) isFromThreadTimeline = partialState.isFromThreadTimeline(),
rootThreadEventId = partialState.rootThreadEventId
)
}
return event.root.isRedacted() && (nextDisplayableEvent?.root?.isRedacted() == false || addDaySeparator)
} }
private fun buildSameTypeEventsMergedSummary( private fun buildSameTypeEventsMergedSummary(

View file

@ -151,16 +151,20 @@ class TimelineEventVisibilityHelper @Inject constructor(
rootThreadEventId: String?, rootThreadEventId: String?,
isFromThreadTimeline: Boolean isFromThreadTimeline: Boolean
): List<TimelineEvent> { ): List<TimelineEvent> {
val prevSub = timelineEvents val prevDisplayableEvents = timelineEvents.subList(0, index + 1)
.subList(0, index + 1) .filter {
// Ensure to not take the REDACTION events into account shouldShowEvent(
.filter { it.root.getClearType() != EventType.REDACTION } timelineEvent = it,
return prevSub highlightedEventId = eventIdToHighlight,
isFromThreadTimeline = isFromThreadTimeline,
rootThreadEventId = rootThreadEventId)
}
return prevDisplayableEvents
.reversed() .reversed()
.let { .let {
nextEventsUntil(it, 0, minSize, eventIdToHighlight, rootThreadEventId, isFromThreadTimeline, object : PredicateToStopSearch { nextEventsUntil(it, 0, minSize, eventIdToHighlight, rootThreadEventId, isFromThreadTimeline, object : PredicateToStopSearch {
override fun shouldStopSearch(oldEvent: Event, newEvent: Event): Boolean { override fun shouldStopSearch(oldEvent: Event, newEvent: Event): Boolean {
return oldEvent.isRedacted() && !newEvent.isRedacted() return !newEvent.isRedacted()
} }
}) })
} }