mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-02 20:26:47 +01:00
Merge pull request #5659 from SpiritCroc/permalink-failure
Fix endless loading timeline if opened at non-existing event
This commit is contained in:
commit
94099f4908
1
changelog.d/5659.bugfix
Normal file
1
changelog.d/5659.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix endless loading if the event from a permalink is not found
|
@ -223,7 +223,15 @@ internal class DefaultTimeline(private val roomId: String,
|
|||||||
updateState(direction) {
|
updateState(direction) {
|
||||||
it.copy(loading = true)
|
it.copy(loading = true)
|
||||||
}
|
}
|
||||||
val loadMoreResult = strategy.loadMore(count, direction, fetchOnServerIfNeeded)
|
val loadMoreResult = try {
|
||||||
|
strategy.loadMore(count, direction, fetchOnServerIfNeeded)
|
||||||
|
} catch (throwable: Throwable) {
|
||||||
|
// Timeline could not be loaded with a (likely) permanent issue, such as the
|
||||||
|
// server now knowing the initialEventId, so we want to show an error message
|
||||||
|
// and possibly restart without initialEventId.
|
||||||
|
onTimelineFailure(throwable)
|
||||||
|
return false
|
||||||
|
}
|
||||||
Timber.v("$baseLogMessage: result $loadMoreResult")
|
Timber.v("$baseLogMessage: result $loadMoreResult")
|
||||||
val hasMoreToLoad = loadMoreResult != LoadMoreResult.REACHED_END
|
val hasMoreToLoad = loadMoreResult != LoadMoreResult.REACHED_END
|
||||||
updateState(direction) {
|
updateState(direction) {
|
||||||
@ -342,6 +350,14 @@ internal class DefaultTimeline(private val roomId: String,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun onTimelineFailure(throwable: Throwable) {
|
||||||
|
timelineScope.launch(coroutineDispatchers.main) {
|
||||||
|
listeners.forEach {
|
||||||
|
tryOrNull { it.onTimelineFailure(throwable) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun buildStrategy(mode: LoadTimelineStrategy.Mode): LoadTimelineStrategy {
|
private fun buildStrategy(mode: LoadTimelineStrategy.Mode): LoadTimelineStrategy {
|
||||||
return LoadTimelineStrategy(
|
return LoadTimelineStrategy(
|
||||||
roomId = roomId,
|
roomId = roomId,
|
||||||
|
@ -24,6 +24,8 @@ import io.realm.RealmResults
|
|||||||
import io.realm.kotlin.createObject
|
import io.realm.kotlin.createObject
|
||||||
import kotlinx.coroutines.CompletableDeferred
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
import org.matrix.android.sdk.api.extensions.orFalse
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
|
import org.matrix.android.sdk.api.failure.Failure
|
||||||
|
import org.matrix.android.sdk.api.failure.MatrixError
|
||||||
import org.matrix.android.sdk.api.session.room.send.SendState
|
import org.matrix.android.sdk.api.session.room.send.SendState
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.Timeline
|
import org.matrix.android.sdk.api.session.room.timeline.Timeline
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
||||||
@ -194,6 +196,10 @@ internal class LoadTimelineStrategy(
|
|||||||
getContextLatch?.await()
|
getContextLatch?.await()
|
||||||
getContextLatch = null
|
getContextLatch = null
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
|
if (failure is Failure.ServerError && failure.error.code in listOf(MatrixError.M_NOT_FOUND, MatrixError.M_FORBIDDEN)) {
|
||||||
|
// This failure is likely permanent, so handle in DefaultTimeline to restart without eventId
|
||||||
|
throw failure
|
||||||
|
}
|
||||||
return LoadMoreResult.FAILURE
|
return LoadMoreResult.FAILURE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user