From 9e63ebae836f64163ac1a9b5c4d772b576112131 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 9 Feb 2017 16:24:32 +0100 Subject: resend failed uploads automatically if filesize smaller than configured AutoAcceptFilesize --- .../de/pixart/messenger/entities/Conversation.java | 16 +++++++++++ .../messenger/services/XmppConnectionService.java | 33 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'src/main/java/de/pixart') diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index db06ecb93..f643cb888 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import de.pixart.messenger.Config; import de.pixart.messenger.crypto.PgpDecryptionService; import de.pixart.messenger.crypto.axolotl.AxolotlService; +import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.xmpp.chatstate.ChatState; import de.pixart.messenger.xmpp.jid.InvalidJidException; import de.pixart.messenger.xmpp.jid.Jid; @@ -94,6 +95,8 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl private Message correctingMessage; public AtomicBoolean messagesLoaded = new AtomicBoolean(true); + XmppConnectionService mXmppConnectionService; + public boolean hasMessagesLeftOnServer() { return messagesLeftOnServer; } @@ -160,6 +163,19 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } } + public void findFailedMessagesWithFiles(final OnMessageFound onMessageFound) { + synchronized (this.messages) { + for (final Message message : this.messages) { + if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) + && message.getEncryption() != Message.ENCRYPTION_PGP) { + if (message.getStatus() == Message.STATUS_SEND_FAILED && !message.isDeleted()) { + onMessageFound.onMessageFound(message); + } + } + } + } + } + public Message findMessageWithFileAndUuid(final String uuid) { synchronized (this.messages) { for (final Message message : this.messages) { diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 729079f2a..5065d4242 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -173,6 +173,8 @@ public class XmppConnectionService extends Service { private WakeLock wakeLock; private long mLastActivity = 0; private NotificationManager mNotifyManager; + AbstractConnectionManager mAbstractConnectionManager; + private ContentObserver contactObserver = new ContentObserver(null) { @Override public void onChange(boolean selfChange) { @@ -345,6 +347,7 @@ public class XmppConnectionService extends Service { Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": couldn't start OTR with " + conversation.getContact().getJid() + " when needed"); } sendUnsentMessages(conversation); + resendFailedFileMessages(conversation); } } for (Conversation conversation : account.pendingConferenceLeaves) { @@ -1404,6 +1407,36 @@ public class XmppConnectionService extends Service { }); } + private long AcceptFileSize() { + String config = "0"; + SharedPreferences sharedPref = getPreferences(); + if (isWIFI()) { + config = sharedPref.getString("auto_accept_file_size_wifi", "10485760"); + } else if (isMobile() && !isMobileRoaming()) { + config = sharedPref.getString("auto_accept_file_size_mobile", "262144"); + } else if (isMobile() && isMobileRoaming()) { + config = sharedPref.getString("auto_accept_file_size_roaming", "1"); + } + + try { + return Long.parseLong(config); + } catch (NumberFormatException e) { + return 1048576; + } + } + + private void resendFailedFileMessages(final Conversation conversation) { + conversation.findFailedMessagesWithFiles(new Conversation.OnMessageFound() { + + @Override + public void onMessageFound(Message message) { + if (AcceptFileSize() >= message.getFileParams().size) { + resendMessage(message, true); + } + } + }); + } + public void resendMessage(final Message message, final boolean delay) { sendMessage(message, true, delay); } -- cgit v1.2.3