diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-02-09 16:24:32 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-02-09 16:24:32 +0100 |
commit | 9e63ebae836f64163ac1a9b5c4d772b576112131 (patch) | |
tree | 7b1be6beecc87689eb85fd8337add36176d1de4d /src/main/java/de/pixart | |
parent | 49fb5e29cd931a504bd414c3398cb0e39fa17da6 (diff) |
resend failed uploads automatically if filesize smaller than configured AutoAcceptFilesize
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r-- | src/main/java/de/pixart/messenger/entities/Conversation.java | 16 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 33 |
2 files changed, 49 insertions, 0 deletions
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); } |