1
0
Fork 1

Catch concurrent modification and abort

Someone added an attachment while we were sending or what?

(cherry picked from commit c4f751e2dd6b0f1bbb56704a3f95e76152989389)
This commit is contained in:
Stephen Paul Weber 2024-11-28 10:21:05 -05:00 committed by Arne
parent d2ef9e3428
commit 475c01cbc6

View file

@ -1524,22 +1524,27 @@ public class ConversationFragment extends XmppFragment
final Runnable next = new Runnable() { final Runnable next = new Runnable() {
@Override @Override
public void run() { public void run() {
final Attachment attachment = i.next(); try {
if (attachment.getType() == Attachment.Type.LOCATION) { final Attachment attachment = i.next();
attachLocationToConversation(conversation, attachment.getUri()); if (attachment.getType() == Attachment.Type.LOCATION) {
if (i.hasNext()) runOnUiThread(this); attachLocationToConversation(conversation, attachment.getUri());
} else if (attachment.getType() == Attachment.Type.IMAGE) { if (i.hasNext()) runOnUiThread(this);
Log.d( } else if (attachment.getType() == Attachment.Type.IMAGE) {
Config.LOGTAG, Log.d(
"ConversationsActivity.commitAttachments() - attaching image to conversations. CHOOSE_IMAGE"); Config.LOGTAG,
attachImageToConversation(conversation, attachment.getUri(), attachment.getMime(), i.hasNext() ? this : null); "ConversationsActivity.commitAttachments() - attaching image to conversations. CHOOSE_IMAGE");
} else { attachImageToConversation(conversation, attachment.getUri(), attachment.getMime(), i.hasNext() ? this : null);
Log.d( } else {
Config.LOGTAG, Log.d(
"ConversationsActivity.commitAttachments() - attaching file to conversations. CHOOSE_FILE/RECORD_VOICE/RECORD_VIDEO"); Config.LOGTAG,
attachFileToConversation(conversation, attachment.getUri(), attachment.getMime(), i.hasNext() ? this : null); "ConversationsActivity.commitAttachments() - attaching file to conversations. CHOOSE_FILE/RECORD_VOICE/RECORD_VIDEO");
attachFileToConversation(conversation, attachment.getUri(), attachment.getMime(), i.hasNext() ? this : null);
}
i.remove();
} catch (final java.util.ConcurrentModificationException e) {
// Abort, leave any unsent attachments alone for the user to try again
Toast.makeText(activity, "Sometimes went wrong with some attachments. Try again?", Toast.LENGTH_SHORT).show();
} }
i.remove();
mediaPreviewAdapter.notifyDataSetChanged(); mediaPreviewAdapter.notifyDataSetChanged();
toggleInputMethod(); toggleInputMethod();
} }