fix scheduling posts (#4392)

Mastodon returns different reponses when posting normally and when
scheduling. This was previously ignored silently, but Moshi is more
correct than Gson and fails, which causes the `SendStatusService` to
retry sending forever and a lot of posts are scheduled.
Mastodon should actually ignore multiple attempts at scheduling the same
post, but doesn't so I filed this
https://github.com/mastodon/mastodon/issues/30039

cc @cbeyls
This commit is contained in:
Konrad Pozniak 2024-04-25 17:08:57 +02:00 committed by GitHub
commit c55d79562c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 12 deletions

View file

@ -49,6 +49,7 @@ import com.keylesspalace.tusky.entity.Attachment
import com.keylesspalace.tusky.entity.MediaAttribute
import com.keylesspalace.tusky.entity.NewPoll
import com.keylesspalace.tusky.entity.NewStatus
import com.keylesspalace.tusky.entity.ScheduledStatus
import com.keylesspalace.tusky.entity.Status
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.util.unsafeLazy
@ -256,13 +257,24 @@ class SendStatusService : Service(), Injectable {
}
)
val scheduled = !statusToSend.scheduledAt.isNullOrEmpty()
val sendResult = if (isNew) {
mastodonApi.createStatus(
"Bearer " + account.accessToken,
account.domain,
statusToSend.idempotencyKey,
newStatus
)
if (!scheduled) {
mastodonApi.createStatus(
"Bearer " + account.accessToken,
account.domain,
statusToSend.idempotencyKey,
newStatus
)
} else {
mastodonApi.createScheduledStatus(
"Bearer " + account.accessToken,
account.domain,
statusToSend.idempotencyKey,
newStatus
)
}
} else {
mastodonApi.editStatus(
statusToSend.statusId!!,
@ -282,14 +294,12 @@ class SendStatusService : Service(), Injectable {
mediaUploader.cancelUploadScope(*statusToSend.media.map { it.localId }.toIntArray())
val scheduled = !statusToSend.scheduledAt.isNullOrEmpty()
if (scheduled) {
eventHub.dispatch(StatusScheduledEvent(sentStatus))
eventHub.dispatch(StatusScheduledEvent(sentStatus as ScheduledStatus))
} else if (!isNew) {
eventHub.dispatch(StatusChangedEvent(sentStatus))
eventHub.dispatch(StatusChangedEvent(sentStatus as Status))
} else {
eventHub.dispatch(StatusComposedEvent(sentStatus))
eventHub.dispatch(StatusComposedEvent(sentStatus as Status))
}
notificationManager.cancel(statusId)