Skip to content

Commit 15a252b

Browse files
authored
Merge pull request #8841 from element-hq/feature/fga/fix_redacted_collapse
Fix redacted events not grouped correctly
2 parents 47bb23a + 2158aa0 commit 15a252b

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

changelog.d/8840.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix redacted events not grouped correctly when hidden events are inserted between.

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class MergedHeaderItemFactory @Inject constructor(
8484
buildRoomCreationMergedSummary(currentPosition, items, partialState, event, eventIdToHighlight, requestModelBuild, callback)
8585
isStartOfSameTypeEventsSummary(event, nextEvent, addDaySeparator) ->
8686
buildSameTypeEventsMergedSummary(currentPosition, items, partialState, event, eventIdToHighlight, requestModelBuild, callback)
87-
isStartOfRedactedEventsSummary(event, items, currentPosition, addDaySeparator) ->
87+
isStartOfRedactedEventsSummary(event, items, currentPosition, partialState, addDaySeparator) ->
8888
buildRedactedEventsMergedSummary(currentPosition, items, partialState, event, eventIdToHighlight, requestModelBuild, callback)
8989
else -> null
9090
}
@@ -122,19 +122,25 @@ class MergedHeaderItemFactory @Inject constructor(
122122
* @param event the main timeline event
123123
* @param items all known items, sorted from newer event to oldest event
124124
* @param currentPosition the current position
125+
* @param partialState partial state data
125126
* @param addDaySeparator true to add a day separator
126127
*/
127128
private fun isStartOfRedactedEventsSummary(
128129
event: TimelineEvent,
129130
items: List<TimelineEvent>,
130131
currentPosition: Int,
132+
partialState: TimelineEventController.PartialState,
131133
addDaySeparator: Boolean,
132134
): Boolean {
133-
val nextNonRedactionEvent = items
134-
.subList(fromIndex = currentPosition + 1, toIndex = items.size)
135-
.find { it.root.getClearType() != EventType.REDACTION }
136-
return event.root.isRedacted() &&
137-
(!nextNonRedactionEvent?.root?.isRedacted().orFalse() || addDaySeparator)
135+
val nextDisplayableEvent = items.subList(currentPosition + 1, items.size).firstOrNull {
136+
timelineEventVisibilityHelper.shouldShowEvent(
137+
timelineEvent = it,
138+
highlightedEventId = partialState.highlightedEventId,
139+
isFromThreadTimeline = partialState.isFromThreadTimeline(),
140+
rootThreadEventId = partialState.rootThreadEventId
141+
)
142+
}
143+
return event.root.isRedacted() && (nextDisplayableEvent?.root?.isRedacted() == false || addDaySeparator)
138144
}
139145

140146
private fun buildSameTypeEventsMergedSummary(

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineEventVisibilityHelper.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,20 @@ class TimelineEventVisibilityHelper @Inject constructor(
151151
rootThreadEventId: String?,
152152
isFromThreadTimeline: Boolean
153153
): List<TimelineEvent> {
154-
val prevSub = timelineEvents
155-
.subList(0, index + 1)
156-
// Ensure to not take the REDACTION events into account
157-
.filter { it.root.getClearType() != EventType.REDACTION }
158-
return prevSub
154+
val prevDisplayableEvents = timelineEvents.subList(0, index + 1)
155+
.filter {
156+
shouldShowEvent(
157+
timelineEvent = it,
158+
highlightedEventId = eventIdToHighlight,
159+
isFromThreadTimeline = isFromThreadTimeline,
160+
rootThreadEventId = rootThreadEventId)
161+
}
162+
return prevDisplayableEvents
159163
.reversed()
160164
.let {
161165
nextEventsUntil(it, 0, minSize, eventIdToHighlight, rootThreadEventId, isFromThreadTimeline, object : PredicateToStopSearch {
162166
override fun shouldStopSearch(oldEvent: Event, newEvent: Event): Boolean {
163-
return oldEvent.isRedacted() && !newEvent.isRedacted()
167+
return !newEvent.isRedacted()
164168
}
165169
})
166170
}

0 commit comments

Comments
 (0)