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:
commit
1d89889f7c
|
@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue