improve check for media upload status (#2720)
This commit is contained in:
parent
050891ebe5
commit
2481bc0523
|
@ -137,8 +137,15 @@ class SendStatusService : Service(), Injectable {
|
||||||
delay(1000L * mediaCheckRetries)
|
delay(1000L * mediaCheckRetries)
|
||||||
statusToSend.mediaProcessed.forEachIndexed { index, processed ->
|
statusToSend.mediaProcessed.forEachIndexed { index, processed ->
|
||||||
if (!processed) {
|
if (!processed) {
|
||||||
// Mastodon returns 206 if the media was not yet processed
|
when (mastodonApi.getMedia(statusToSend.mediaIds[index]).code()) {
|
||||||
statusToSend.mediaProcessed[index] = mastodonApi.getMedia(statusToSend.mediaIds[index]).code() == 200
|
200 -> statusToSend.mediaProcessed[index] = true // success
|
||||||
|
206 -> { } // media is still being processed, continue checking
|
||||||
|
else -> { // some kind of server error, retrying probably doesn't make sense
|
||||||
|
failSending(statusId)
|
||||||
|
stopSelfWhenDone()
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mediaCheckRetries ++
|
mediaCheckRetries ++
|
||||||
|
@ -186,18 +193,7 @@ class SendStatusService : Service(), Injectable {
|
||||||
Log.w(TAG, "failed sending status", throwable)
|
Log.w(TAG, "failed sending status", throwable)
|
||||||
if (throwable is HttpException) {
|
if (throwable is HttpException) {
|
||||||
// the server refused to accept the status, save status & show error message
|
// the server refused to accept the status, save status & show error message
|
||||||
statusesToSend.remove(statusId)
|
failSending(statusId)
|
||||||
saveStatusToDrafts(statusToSend)
|
|
||||||
|
|
||||||
val notification = buildDraftNotification(
|
|
||||||
R.string.send_post_notification_error_title,
|
|
||||||
R.string.send_post_notification_saved_content,
|
|
||||||
statusToSend.accountId,
|
|
||||||
statusId
|
|
||||||
)
|
|
||||||
|
|
||||||
notificationManager.cancel(statusId)
|
|
||||||
notificationManager.notify(errorNotificationId--, notification)
|
|
||||||
} else {
|
} else {
|
||||||
// a network problem occurred, let's retry sending the status
|
// a network problem occurred, let's retry sending the status
|
||||||
retrySending(statusId)
|
retrySending(statusId)
|
||||||
|
@ -225,6 +221,24 @@ class SendStatusService : Service(), Injectable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun failSending(statusId: Int) {
|
||||||
|
val failedStatus = statusesToSend.remove(statusId)
|
||||||
|
if (failedStatus != null) {
|
||||||
|
|
||||||
|
saveStatusToDrafts(failedStatus)
|
||||||
|
|
||||||
|
val notification = buildDraftNotification(
|
||||||
|
R.string.send_post_notification_error_title,
|
||||||
|
R.string.send_post_notification_saved_content,
|
||||||
|
failedStatus.accountId,
|
||||||
|
statusId
|
||||||
|
)
|
||||||
|
|
||||||
|
notificationManager.cancel(statusId)
|
||||||
|
notificationManager.notify(errorNotificationId++, notification)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun cancelSending(statusId: Int) = serviceScope.launch {
|
private fun cancelSending(statusId: Int) = serviceScope.launch {
|
||||||
val statusToCancel = statusesToSend.remove(statusId)
|
val statusToCancel = statusesToSend.remove(statusId)
|
||||||
if (statusToCancel != null) {
|
if (statusToCancel != null) {
|
||||||
|
|
Loading…
Reference in New Issue