Restart the timeline when some Event are deleted, for instance when ignoring a user, for the change to take effect

This commit is contained in:
Benoit Marty 2022-04-15 16:30:09 +02:00
parent cc8f086cc3
commit 903e226e59
3 changed files with 21 additions and 4 deletions

View file

@ -100,6 +100,7 @@ internal class DefaultTimeline(private val roomId: String,
threadsAwarenessHandler = threadsAwarenessHandler,
lightweightSettingsStorage = lightweightSettingsStorage,
onEventsUpdated = this::sendSignalToPostSnapshot,
onEventsDeleted = this::onEventsDeleted,
onLimitedTimeline = this::onLimitedTimeline,
onNewTimelineEvents = this::onNewTimelineEvents
)
@ -304,6 +305,12 @@ internal class DefaultTimeline(private val roomId: String,
}
}
private fun onEventsDeleted() {
// Some event have been deleted, for instance when a user has been ignored.
// Restart the timeline (live)
restartWithEventId(null)
}
private suspend fun postSnapshot() {
val snapshot = strategy.buildSnapshot()
Timber.v("Post snapshot of ${snapshot.size} events")

View file

@ -95,6 +95,7 @@ internal class LoadTimelineStrategy(
val threadsAwarenessHandler: ThreadsAwarenessHandler,
val lightweightSettingsStorage: LightweightSettingsStorage,
val onEventsUpdated: (Boolean) -> Unit,
val onEventsDeleted: () -> Unit,
val onLimitedTimeline: () -> Unit,
val onNewTimelineEvents: (List<String>) -> Unit
)
@ -302,7 +303,8 @@ internal class LoadTimelineStrategy(
threadsAwarenessHandler = dependencies.threadsAwarenessHandler,
lightweightSettingsStorage = dependencies.lightweightSettingsStorage,
initialEventId = mode.originEventId(),
onBuiltEvents = dependencies.onEventsUpdated
onBuiltEvents = dependencies.onEventsUpdated,
onEventsDeleted = dependencies.onEventsDeleted,
)
}
}

View file

@ -59,11 +59,13 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity,
private val realmConfiguration: RealmConfiguration,
private val fetchTokenAndPaginateTask: FetchTokenAndPaginateTask,
private val timelineEventMapper: TimelineEventMapper,
private val uiEchoManager: UIEchoManager? = null,
private val uiEchoManager: UIEchoManager?,
private val threadsAwarenessHandler: ThreadsAwarenessHandler,
private val lightweightSettingsStorage: LightweightSettingsStorage,
private val initialEventId: String?,
private val onBuiltEvents: (Boolean) -> Unit) {
private val onBuiltEvents: (Boolean) -> Unit,
private val onEventsDeleted: () -> Unit,
) {
private val isLastForward = AtomicBoolean(chunkEntity.isLastForward)
private val isLastBackward = AtomicBoolean(chunkEntity.isLastBackward)
@ -505,6 +507,11 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity,
if (insertions.isNotEmpty() || modifications.isNotEmpty()) {
onBuiltEvents(true)
}
val deletions = changeSet.deletions
if (deletions.isNotEmpty()) {
onEventsDeleted()
}
}
private fun getNextDisplayIndex(direction: Timeline.Direction): Int? {
@ -543,7 +550,8 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity,
threadsAwarenessHandler = threadsAwarenessHandler,
lightweightSettingsStorage = lightweightSettingsStorage,
initialEventId = null,
onBuiltEvents = this.onBuiltEvents
onBuiltEvents = this.onBuiltEvents,
onEventsDeleted = this.onEventsDeleted
)
}