mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Added long polling
This commit is contained in:
parent
fc4ea70621
commit
6928bfa2ae
@ -24,6 +24,7 @@ import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
|
||||
import com.google.android.gms.security.ProviderInstaller;
|
||||
@ -52,6 +53,7 @@ import org.thoughtcrime.securesms.logging.CustomSignalProtocolLogger;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.logging.PersistentLogger;
|
||||
import org.thoughtcrime.securesms.logging.UncaughtExceptionLogger;
|
||||
import org.thoughtcrime.securesms.loki.LokiAPIDatabase;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.providers.BlobProvider;
|
||||
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
|
||||
@ -70,6 +72,8 @@ import org.webrtc.PeerConnectionFactory.InitializationOptions;
|
||||
import org.webrtc.voiceengine.WebRtcAudioManager;
|
||||
import org.webrtc.voiceengine.WebRtcAudioUtils;
|
||||
import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider;
|
||||
import org.whispersystems.signalservice.loki.api.LokiAPI;
|
||||
import org.whispersystems.signalservice.loki.api.LokiLongPoller;
|
||||
import org.whispersystems.signalservice.loki.api.LokiP2PAPI;
|
||||
import org.whispersystems.signalservice.loki.api.LokiP2PAPIDelegate;
|
||||
|
||||
@ -101,6 +105,8 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
private ObjectGraph objectGraph;
|
||||
private PersistentLogger persistentLogger;
|
||||
|
||||
private LokiLongPoller lokiLongPoller = null;
|
||||
|
||||
private volatile boolean isAppVisible;
|
||||
|
||||
public static ApplicationContext getInstance(Context context) {
|
||||
@ -149,6 +155,9 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
Log.i(TAG, "App is now visible.");
|
||||
executePendingContactSync();
|
||||
KeyCachingService.onAppForegrounded(this);
|
||||
|
||||
// Start message receiving if we have registered
|
||||
startLokiLongPolling();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -156,6 +165,10 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
isAppVisible = false;
|
||||
Log.i(TAG, "App is no longer visible.");
|
||||
KeyCachingService.onAppBackgrounded(this);
|
||||
|
||||
if (lokiLongPoller != null) {
|
||||
lokiLongPoller.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -189,6 +202,24 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
return persistentLogger;
|
||||
}
|
||||
|
||||
public void startLokiLongPolling() {
|
||||
initializeLokiLongPoller();
|
||||
if (lokiLongPoller != null) {
|
||||
lokiLongPoller.startIfNecessary();
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeLokiLongPoller() {
|
||||
if (lokiLongPoller != null) return;
|
||||
|
||||
String hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
|
||||
if (hexEncodedPublicKey == null) return;
|
||||
|
||||
LokiAPIDatabase database = DatabaseFactory.getLokiAPIDatabase(this);
|
||||
LokiAPI lokiAPI = new LokiAPI(hexEncodedPublicKey, database);
|
||||
lokiLongPoller = new LokiLongPoller(hexEncodedPublicKey, lokiAPI);
|
||||
}
|
||||
|
||||
private void initializeSecurityProvider() {
|
||||
try {
|
||||
Class.forName("org.signal.aesgcmprovider.AesGcmCipher");
|
||||
|
@ -7,6 +7,7 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import kotlinx.android.synthetic.main.activity_key_pair.*
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.BaseActionBarActivity
|
||||
import org.thoughtcrime.securesms.ConversationListActivity
|
||||
import org.thoughtcrime.securesms.R
|
||||
@ -96,6 +97,9 @@ class KeyPairActivity : BaseActionBarActivity() {
|
||||
|
||||
// TODO: Configure P2P API
|
||||
|
||||
// Loki - start the long polling
|
||||
ApplicationContext.getInstance(this).startLokiLongPolling()
|
||||
|
||||
startActivity(Intent(this, ConversationListActivity::class.java))
|
||||
finish()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user