Handle status edit histories with < 2 entries (#3747)
This can happen if the edit history has not been propogated to the user's server. If the edit history is missing then show an error with a link to the specifc Mastodon issue. Fixes #3743
This commit is contained in:
parent
c3ad055092
commit
100673aa9c
5 changed files with 85 additions and 61 deletions
|
@ -111,16 +111,31 @@ class ViewEditsFragment :
|
|||
binding.statusView.show()
|
||||
binding.initialProgressBar.hide()
|
||||
|
||||
if (uiState.throwable is IOException) {
|
||||
binding.statusView.setup(R.drawable.elephant_offline, R.string.error_network) {
|
||||
when (uiState.throwable) {
|
||||
is IOException -> {
|
||||
binding.statusView.setup(
|
||||
R.drawable.elephant_offline,
|
||||
R.string.error_network
|
||||
) {
|
||||
viewModel.loadEdits(statusId, force = true)
|
||||
}
|
||||
} else {
|
||||
binding.statusView.setup(R.drawable.elephant_error, R.string.error_generic) {
|
||||
}
|
||||
is ViewEditsViewModel.MissingEditsException -> {
|
||||
binding.statusView.setup(
|
||||
R.drawable.elephant_friend_empty,
|
||||
R.string.error_missing_edits
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
binding.statusView.setup(
|
||||
R.drawable.elephant_error,
|
||||
R.string.error_generic
|
||||
) {
|
||||
viewModel.loadEdits(statusId, force = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
is EditsUiState.Success -> {
|
||||
binding.swipeRefreshLayout.isRefreshing = false
|
||||
binding.recyclerView.show()
|
||||
|
|
|
@ -17,7 +17,7 @@ package com.keylesspalace.tusky.components.viewthread.edits
|
|||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import at.connyduck.calladapter.networkresult.fold
|
||||
import at.connyduck.calladapter.networkresult.getOrElse
|
||||
import com.keylesspalace.tusky.components.viewthread.edits.TuskyTagHandler.Companion.DELETED_TEXT_EL
|
||||
import com.keylesspalace.tusky.components.viewthread.edits.TuskyTagHandler.Companion.INSERTED_TEXT_EL
|
||||
import com.keylesspalace.tusky.entity.StatusEdit
|
||||
|
@ -48,6 +48,9 @@ class ViewEditsViewModel @Inject constructor(private val api: MastodonApi) : Vie
|
|||
private val _uiState: MutableStateFlow<EditsUiState> = MutableStateFlow(EditsUiState.Initial)
|
||||
val uiState: StateFlow<EditsUiState> = _uiState.asStateFlow()
|
||||
|
||||
/** The API call to fetch edit history returned less than two items */
|
||||
object MissingEditsException : Exception()
|
||||
|
||||
fun loadEdits(statusId: String, force: Boolean = false, refreshing: Boolean = false) {
|
||||
if (!force && _uiState.value !is EditsUiState.Initial) return
|
||||
|
||||
|
@ -58,8 +61,18 @@ class ViewEditsViewModel @Inject constructor(private val api: MastodonApi) : Vie
|
|||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
api.statusEdits(statusId).fold(
|
||||
{ edits ->
|
||||
val edits = api.statusEdits(statusId).getOrElse {
|
||||
_uiState.value = EditsUiState.Error(it)
|
||||
return@launch
|
||||
}
|
||||
|
||||
// `edits` might have fewer than the minimum number of entries because of
|
||||
// https://github.com/mastodon/mastodon/issues/25398.
|
||||
if (edits.size < 2) {
|
||||
_uiState.value = EditsUiState.Error(MissingEditsException)
|
||||
return@launch
|
||||
}
|
||||
|
||||
// Diff each status' content against the previous version, producing new
|
||||
// content with additional `ins` or `del` elements marking inserted or
|
||||
// deleted content.
|
||||
|
@ -110,11 +123,6 @@ class ViewEditsViewModel @Inject constructor(private val api: MastodonApi) : Vie
|
|||
_uiState.value = EditsUiState.Success(sortedEdits)
|
||||
}
|
||||
}
|
||||
},
|
||||
{ throwable ->
|
||||
_uiState.value = EditsUiState.Error(throwable)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.keylesspalace.tusky.view
|
||||
|
||||
import android.content.Context
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.util.AttributeSet
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
|
@ -44,6 +45,7 @@ class BackgroundMessageView @JvmOverloads constructor(
|
|||
clickListener: ((v: View) -> Unit)? = null
|
||||
) {
|
||||
binding.messageTextView.setText(messageRes)
|
||||
binding.messageTextView.movementMethod = LinkMovementMethod.getInstance()
|
||||
binding.imageView.setImageResource(imageRes)
|
||||
binding.button.setOnClickListener(clickListener)
|
||||
binding.button.visible(clickListener != null)
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
android:scaleType="centerInside"
|
||||
android:src="@drawable/elephant_offline" />
|
||||
|
||||
<TextView
|
||||
<com.keylesspalace.tusky.view.ClickableSpanTextView
|
||||
android:id="@+id/messageTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -764,10 +764,9 @@
|
|||
<string name="pref_reading_order_oldest_first">Oldest first</string>
|
||||
<string name="pref_reading_order_newest_first">Newest first</string>
|
||||
|
||||
<!--@Tusky edited 19th December 2022 13:37 -->
|
||||
<string name="status_edit_info">Edited: %1$s</string>
|
||||
<!--@Tusky created 19th December 2022 13:12 -->
|
||||
<string name="status_created_info">Created: %1$s</string>
|
||||
<string name="error_missing_edits">Your server knows that this post was edited, but does not have a copy of the edits, so they can\'t be shown to you.\n\nThis is <a href="https://github.com/mastodon/mastodon/issues/25398">Mastodon issue #25398</a>.</string>
|
||||
<string name="a11y_label_loading_thread">Loading thread</string>
|
||||
|
||||
<!--@knossos@fosstodon.org created 2023-01-07 -->
|
||||
|
|
Loading…
Reference in a new issue