Merge pull request #1281 from Xefir/fix-mastodon-upload-alt-text

Backport #1007 Fix Mastodon upload image with description (alt text)
This commit is contained in:
Tlaster 2020-04-28 13:33:21 +08:00 committed by GitHub
commit 1d89889f7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -18,6 +18,8 @@
package org.mariotaku.microblog.library.mastodon.api; package org.mariotaku.microblog.library.mastodon.api;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.mariotaku.microblog.library.MicroBlogException; import org.mariotaku.microblog.library.MicroBlogException;
import org.mariotaku.microblog.library.mastodon.model.Attachment; import org.mariotaku.microblog.library.mastodon.model.Attachment;
import org.mariotaku.restfu.annotation.method.POST; import org.mariotaku.restfu.annotation.method.POST;
@ -33,6 +35,7 @@ public interface MediaResources {
@POST("/v1/media") @POST("/v1/media")
@BodyType(BodyType.MULTIPART) @BodyType(BodyType.MULTIPART)
Attachment uploadMediaAttachment(@Param("file") Body body) throws MicroBlogException; Attachment uploadMediaAttachment(@NonNull @Param("file") Body body,
@Nullable @Param("description") String description) throws MicroBlogException;
} }

View File

@ -745,17 +745,17 @@ class UpdateStatusTask(
chucked: Boolean, callback: UploadCallback?): SharedMediaUploadResult { chucked: Boolean, callback: UploadCallback?): SharedMediaUploadResult {
val deleteOnSuccess = ArrayList<MediaDeletionItem>() val deleteOnSuccess = ArrayList<MediaDeletionItem>()
val deleteAlways = ArrayList<MediaDeletionItem>() val deleteAlways = ArrayList<MediaDeletionItem>()
val mediaIds = media.mapIndexedToArray { index, media -> val mediaIds = media.mapIndexedToArray { index, item ->
val resp: Attachment val resp: Attachment
//noinspection TryWithIdenticalCatches //noinspection TryWithIdenticalCatches
var body: MediaStreamBody? = null var body: MediaStreamBody? = null
try { try {
val sizeLimit = account.getMediaSizeLimit() val sizeLimit = account.getMediaSizeLimit()
body = getBodyFromMedia(context, media, sizeLimit, chucked, body = getBodyFromMedia(context, item, sizeLimit, chucked,
ContentLengthInputStream.ReadListener { length, position -> ContentLengthInputStream.ReadListener { length, position ->
callback?.onUploadingProgressChanged(index, position, length) callback?.onUploadingProgressChanged(index, position, length)
}) })
resp = mastodon.uploadMediaAttachment(body.body) resp = mastodon.uploadMediaAttachment(body.body, item.alt_text)
} catch (e: IOException) { } catch (e: IOException) {
throw UploadException(e).apply { throw UploadException(e).apply {
this.deleteAlways = deleteAlways this.deleteAlways = deleteAlways