forked from mirrors/Fedilab
Fix issue #99 - Add retry when media failed to load and if 3 retries fail the message is kept in drafts but not send
This commit is contained in:
parent
8aad0fd264
commit
79c38746e2
2 changed files with 29 additions and 17 deletions
|
@ -66,9 +66,7 @@ import androidx.navigation.ui.NavigationUI;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
|
||||||
import com.bumptech.glide.load.resource.gif.GifDrawable;
|
import com.bumptech.glide.load.resource.gif.GifDrawable;
|
||||||
import com.bumptech.glide.request.RequestOptions;
|
|
||||||
import com.bumptech.glide.request.target.CustomTarget;
|
import com.bumptech.glide.request.target.CustomTarget;
|
||||||
import com.bumptech.glide.request.transition.Transition;
|
import com.bumptech.glide.request.transition.Transition;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
|
@ -170,21 +170,16 @@ public class PostMessageService extends IntentService {
|
||||||
} else {
|
} else {
|
||||||
fileMultipartBody = Helper.getMultipartBody("file", attachment);
|
fileMultipartBody = Helper.getMultipartBody("file", attachment);
|
||||||
}
|
}
|
||||||
Call<Attachment> attachmentCall = mastodonStatusesService.postMedia(dataPost.token, fileMultipartBody, null, attachment.description, null);
|
String replyId = null;
|
||||||
|
int retry = 0;
|
||||||
if (attachmentCall != null) {
|
while (replyId == null && retry < 3) {
|
||||||
try {
|
replyId = postAttachment(mastodonStatusesService, dataPost, fileMultipartBody, attachment);
|
||||||
Response<Attachment> attachmentResponse = attachmentCall.execute();
|
retry++;
|
||||||
if (attachmentResponse.isSuccessful()) {
|
}
|
||||||
Attachment attachmentReply = attachmentResponse.body();
|
if (replyId == null) {
|
||||||
if (attachmentReply != null) {
|
error = true;
|
||||||
attachmentIds.add(attachmentReply.id);
|
} else {
|
||||||
}
|
attachmentIds.add(replyId);
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
error = true;
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,6 +291,25 @@ public class PostMessageService extends IntentService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String postAttachment(MastodonStatusesService mastodonStatusesService, DataPost dataPost, MultipartBody.Part fileMultipartBody, Attachment attachment) {
|
||||||
|
Call<Attachment> attachmentCall = mastodonStatusesService.postMedia(dataPost.token, fileMultipartBody, null, attachment.description, null);
|
||||||
|
|
||||||
|
if (attachmentCall != null) {
|
||||||
|
try {
|
||||||
|
Response<Attachment> attachmentResponse = attachmentCall.execute();
|
||||||
|
if (attachmentResponse.isSuccessful()) {
|
||||||
|
Attachment attachmentReply = attachmentResponse.body();
|
||||||
|
if (attachmentReply != null) {
|
||||||
|
return attachmentReply.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
Loading…
Reference in a new issue