From f4d8f78ac721bb4f68046df8b3e017eb8546770c Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Thu, 9 Sep 2021 11:29:19 +0200 Subject: [PATCH] Fix timeline rebuild on DM state change Needs slightly different handling after 50a042683b74 "Architecture: get rid of RoomSummariesHolder as it can lead to errors" Change-Id: I1d34ca5058d93a73dc26c3b2fee7f8a296ec4880 --- .../android/sdk/api/session/room/timeline/Timeline.kt | 9 --------- .../internal/session/room/timeline/DefaultTimeline.kt | 6 ------ .../features/home/room/detail/RoomDetailViewModel.kt | 11 ----------- .../room/detail/timeline/TimelineEventController.kt | 8 +++++++- 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/timeline/Timeline.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/timeline/Timeline.kt index ca374d6eae..236441a9aa 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/timeline/Timeline.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/timeline/Timeline.kt @@ -115,11 +115,6 @@ interface Timeline { */ fun getTimelineEventWithId(eventId: String?): TimelineEvent? - /** - * Called when the DM flag of the room is changed - */ - fun onDmStateChanged() - interface Listener { /** * Call when the timeline has been updated through pagination or sync. @@ -138,10 +133,6 @@ interface Timeline { */ fun onNewTimelineEvents(eventIds: List) - /** - * Called when the DM flag of the room is changed - */ - fun onDmStateChanged() } /** 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 c66b60ada5..2c28a10c04 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 @@ -300,12 +300,6 @@ internal class DefaultTimeline( } } - override fun onDmStateChanged() { - listeners.forEach { - it.onDmStateChanged() - } - } - override fun rebuildEvent(eventId: String, builder: (TimelineEvent) -> TimelineEvent?): Boolean { return tryOrNull { builtEventsIdMap[eventId]?.let { builtIndex -> diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt index 2a8d14c8ff..96ffba356f 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt @@ -157,8 +157,6 @@ class RoomDetailViewModel @AssistedInject constructor( private var prepareToEncrypt: Async = Uninitialized - private var previousSummary: RoomSummary? = null - @AssistedFactory interface Factory { fun create(initialState: RoomDetailViewState): RoomDetailViewModel @@ -1612,11 +1610,6 @@ class RoomDetailViewModel @AssistedInject constructor( room.getStateEvent(EventType.STATE_ROOM_TOMBSTONE)?.also { setState { copy(tombstoneEvent = it) } } - val safePreviousSummary = previousSummary - if (safePreviousSummary == null || safePreviousSummary.isDirect != summary.isDirect) { - timeline.onDmStateChanged() - } - previousSummary = summary } } @@ -1657,8 +1650,4 @@ class RoomDetailViewModel @AssistedInject constructor( callManager.removeProtocolsCheckerListener(this) super.onCleared() } - - override fun onDmStateChanged() { - // No-op - } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt index 43f478b002..e347a1325b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt @@ -247,6 +247,12 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec fun update(viewState: RoomDetailViewState) = synchronized(modelCache) { val newPartialState = PartialState(viewState) + if (partialState.roomSummary?.isDirect != newPartialState.roomSummary?.isDirect) { + partialState = newPartialState + invalidateFullTimeline() + // This already called requestModelBuild + return + } if (partialState.highlightedEventId != newPartialState.highlightedEventId) { // Clear cache to force a refresh for (i in 0 until modelCache.size) { @@ -313,7 +319,7 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec // no-op, already handled } - override fun onDmStateChanged() { + private fun invalidateFullTimeline() { backgroundHandler.post { inSubmitList = true // Invalidate all timeline events to rebuild the whole Room/DM layout