フォロー限定投稿にフォロー外から返信しようとした際のエラー表示を改善

This commit is contained in:
tateisu 2023-07-11 09:09:43 +09:00
parent 8dc33e1b70
commit 6ac8545b58
4 changed files with 37 additions and 20 deletions

View File

@ -607,7 +607,19 @@ class PostImpl(
status != null ->
PostResult.Normal(account, status)
else -> error(result.error ?: "(result.error is null)")
else -> {
val e = result.error
error(
when {
e.isNullOrBlank() -> "(missing result.error)"
e.contains("HTTP 404") ->
"$e\n${activity.getString(R.string.post_404_desc)}"
else -> e
}
)
}
}
}
}

View File

@ -1289,4 +1289,5 @@
<string name="use_webp_format_if_server_accepts">可能ならWebPフォーマットを使う</string>
<string name="detail">詳細</string>
<string name="emoji_detail">絵文字の詳細</string>
</resources>
<string name="post_404_desc">(もしくは、フォロー限定投稿にフォロー外から返信しようとしました)</string>
</resources>

View File

@ -1300,4 +1300,5 @@
<string name="use_webp_format_if_server_accepts">Use WebP format if server accepts.</string>
<string name="detail">Detail</string>
<string name="emoji_detail">Emoji detail</string>
<string name="post_404_desc">(Or, you reply to follower-only post from other account)</string>
</resources>

View File

@ -108,7 +108,7 @@ internal fun showToastImpl(
context: Context,
bLong: Boolean,
message: String,
forceToast:Boolean = false,
forceToast: Boolean = false,
): Boolean {
runOnMainLooper {
if (!forceToast && (message.length >= 32 || message.count { it == '\n' } > 1)) {
@ -154,8 +154,8 @@ internal fun showToastImpl(
fun Context.showToast(
bLong: Boolean,
caption: String?,
forceToast:Boolean = false,
): Boolean = showToastImpl(this, bLong, caption ?: "(null)" ,forceToast = forceToast)
forceToast: Boolean = false,
): Boolean = showToastImpl(this, bLong, caption ?: "(null)", forceToast = forceToast)
fun Context.showToast(ex: Throwable, caption: String? = null): Boolean =
showToastImpl(this, true, ex.withCaption(caption))
@ -188,23 +188,26 @@ fun AppCompatActivity.showError(ex: Throwable, caption: String? = null) {
if (ex is CancellationException) return
try {
AlertDialog.Builder(this)
.setTitle("error")
.setMessage(
listOf(
caption,
when (ex) {
is IllegalStateException -> null
else -> ex.javaClass.simpleName
},
ex.message,
)
.filter { !it.isNullOrBlank() }
.joinToString("\n")
)
val text = listOf(
caption,
when (ex) {
is IllegalStateException -> null
else -> ex.javaClass.simpleName
},
ex.message,
)
.filter { !it.isNullOrBlank() }
.joinToString("\n")
if (text.isNotEmpty()) {
AlertDialog.Builder(this)
.setMessage(text)
.setPositiveButton(android.R.string.ok, null)
.show()
return
}
} catch (ignored: Throwable) {
showToast(ex, caption)
}
showToast(ex, caption)
}
fun Context.errorString(@StringRes stringId: Int, vararg args: Any?): Nothing =