diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index 1a7af8b058..e12ea412fb 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -20,17 +20,13 @@ import android.annotation.SuppressLint; import android.arch.lifecycle.DefaultLifecycleObserver; import android.arch.lifecycle.LifecycleOwner; import android.arch.lifecycle.ProcessLifecycleOwner; -import android.content.BroadcastReceiver; import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; import android.database.ContentObserver; import android.os.AsyncTask; import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.multidex.MultiDexApplication; -import android.support.v4.content.LocalBroadcastManager; import com.crashlytics.android.Crashlytics; import com.google.android.gms.security.ProviderInstaller; @@ -91,6 +87,7 @@ import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider; import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope; import org.whispersystems.signalservice.internal.push.SignalServiceProtos; import org.whispersystems.signalservice.loki.api.LokiAPIDatabaseProtocol; +import org.whispersystems.signalservice.loki.api.LokiDotNetAPI; import org.whispersystems.signalservice.loki.api.LokiPublicChat; import org.whispersystems.signalservice.loki.api.LokiPublicChatAPI; import org.whispersystems.signalservice.loki.api.LokiLongPoller; @@ -113,6 +110,7 @@ import io.fabric.sdk.android.Fabric; import kotlin.Unit; import kotlin.jvm.functions.Function1; import network.loki.messenger.BuildConfig; +import okhttp3.Cache; import static nl.komponents.kovenant.android.KovenantAndroid.startKovenant; import static nl.komponents.kovenant.android.KovenantAndroid.stopKovenant; @@ -128,6 +126,7 @@ import static nl.komponents.kovenant.android.KovenantAndroid.stopKovenant; public class ApplicationContext extends MultiDexApplication implements DependencyInjector, DefaultLifecycleObserver, LokiP2PAPIDelegate { private static final String TAG = ApplicationContext.class.getSimpleName(); + private final static int OK_HTTP_CACHE_SIZE = 10 * 1024 * 1024; // 10MB private ExpiringMessageManager expiringMessageManager; private TypingStatusRepository typingStatusRepository; @@ -192,7 +191,8 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc }; // Loki - Set up public chat manager lokiPublicChatManager = new LokiPublicChatManager(this); - + // Loki - Set the cache + LokiDotNetAPI.setCache(new Cache(this.getCacheDir(), OK_HTTP_CACHE_SIZE)); // Loki - Update device mappings if (setUpStorageAPIIfNeeded()) { LokiStorageAPI.Companion.getShared().updateUserDeviceMappings(); diff --git a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java index 108bcab936..ae133a0394 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java @@ -227,8 +227,10 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType { } } catch (UntrustedIdentityException uie) { warn(TAG, "Failure", uie); - database.addMismatchedIdentity(messageId, Address.fromSerialized(uie.getE164Number()), uie.getIdentityKey()); - database.markAsSentFailed(messageId); + if (messageId >= 0) { + database.addMismatchedIdentity(messageId, Address.fromSerialized(uie.getE164Number()), uie.getIdentityKey()); + database.markAsSentFailed(messageId); + } } } diff --git a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java index bfd4839e36..a8a084a447 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java @@ -159,14 +159,18 @@ public class PushTextSendJob extends PushSendJob implements InjectableType { } catch (InsecureFallbackApprovalException e) { warn(TAG, "Failure", e); - database.markAsPendingInsecureSmsFallback(record.getId()); - MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId()); - ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(false)); + if (messageId >= 0) { + database.markAsPendingInsecureSmsFallback(record.getId()); + MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId()); + ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(false)); + } } catch (UntrustedIdentityException e) { warn(TAG, "Failure", e); - database.addMismatchedIdentity(record.getId(), Address.fromSerialized(e.getE164Number()), e.getIdentityKey()); - database.markAsSentFailed(record.getId()); - database.markAsPush(record.getId()); + if (messageId >= 0) { + database.addMismatchedIdentity(record.getId(), Address.fromSerialized(e.getE164Number()), e.getIdentityKey()); + database.markAsSentFailed(record.getId()); + database.markAsPush(record.getId()); + } } }