mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Linked storage api and database.
This commit is contained in:
parent
ff65d4e342
commit
901d627d32
@ -83,12 +83,7 @@ import org.webrtc.voiceengine.WebRtcAudioUtils;
|
||||
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.LokiGroupChat;
|
||||
import org.whispersystems.signalservice.loki.api.LokiGroupChatAPI;
|
||||
import org.whispersystems.signalservice.loki.api.LokiLongPoller;
|
||||
import org.whispersystems.signalservice.loki.api.LokiP2PAPI;
|
||||
import org.whispersystems.signalservice.loki.api.LokiP2PAPIDelegate;
|
||||
import org.whispersystems.signalservice.loki.api.LokiRSSFeed;
|
||||
import org.whispersystems.signalservice.loki.api.*;
|
||||
import org.whispersystems.signalservice.loki.utilities.Analytics;
|
||||
|
||||
import java.security.Security;
|
||||
@ -164,6 +159,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
|
||||
// Loki - Set up P2P API if needed
|
||||
setUpP2PAPI();
|
||||
setUpStorageAPI();
|
||||
// Loki - Set up beta analytics
|
||||
if (!BuildConfig.DEBUG) {
|
||||
Fabric.with(this, new Crashlytics());
|
||||
@ -414,6 +410,10 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
}
|
||||
|
||||
// region Loki
|
||||
public void setUpStorageAPI() {
|
||||
LokiStorageAPI.Companion.configure(DatabaseFactory.getLokiMultiDeviceDatabase(this));
|
||||
}
|
||||
|
||||
public void setUpP2PAPI() {
|
||||
String hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
|
||||
if (hexEncodedPublicKey == null) { return; }
|
||||
|
@ -31,12 +31,7 @@ import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.database.helpers.ClassicOpenHelper;
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherMigrationHelper;
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||
import org.thoughtcrime.securesms.loki.LokiAPIDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyRecordDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiThreadDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiUserDatabase;
|
||||
import org.thoughtcrime.securesms.loki.*;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
public class DatabaseFactory {
|
||||
@ -68,6 +63,7 @@ public class DatabaseFactory {
|
||||
|
||||
// Loki
|
||||
private final LokiAPIDatabase lokiAPIDatabase;
|
||||
private final LokiMultiDeviceDatabase lokiMultiDeviceDatabase;
|
||||
private final LokiPreKeyRecordDatabase lokiContactPreKeyDatabase;
|
||||
private final LokiPreKeyBundleDatabase lokiPreKeyBundleDatabase;
|
||||
private final LokiMessageDatabase lokiMessageDatabase;
|
||||
@ -168,6 +164,10 @@ public class DatabaseFactory {
|
||||
return getInstance(context).lokiAPIDatabase;
|
||||
}
|
||||
|
||||
public static LokiMultiDeviceDatabase getLokiMultiDeviceDatabase(Context context) {
|
||||
return getInstance(context).lokiMultiDeviceDatabase;
|
||||
}
|
||||
|
||||
public static LokiPreKeyRecordDatabase getLokiPreKeyRecordDatabase(Context context) {
|
||||
return getInstance(context).lokiContactPreKeyDatabase;
|
||||
}
|
||||
@ -221,6 +221,7 @@ public class DatabaseFactory {
|
||||
this.jobDatabase = new JobDatabase(context, databaseHelper);
|
||||
this.stickerDatabase = new StickerDatabase(context, databaseHelper, attachmentSecret);
|
||||
this.lokiAPIDatabase = new LokiAPIDatabase(context, databaseHelper);
|
||||
this.lokiMultiDeviceDatabase = new LokiMultiDeviceDatabase(context, databaseHelper);
|
||||
this.lokiContactPreKeyDatabase = new LokiPreKeyRecordDatabase(context, databaseHelper);
|
||||
this.lokiPreKeyBundleDatabase = new LokiPreKeyBundleDatabase(context, databaseHelper);
|
||||
this.lokiMessageDatabase = new LokiMessageDatabase(context, databaseHelper);
|
||||
|
@ -7,9 +7,10 @@ import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.thoughtcrime.securesms.util.Base64
|
||||
import org.whispersystems.signalservice.loki.api.LokiPairingAuthorisation
|
||||
import org.whispersystems.signalservice.loki.api.LokiStorageAPIDatabaseProtocol
|
||||
import java.util.*
|
||||
|
||||
class LokiMultiDeviceDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||
class LokiMultiDeviceDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiStorageAPIDatabaseProtocol {
|
||||
|
||||
companion object {
|
||||
// Authorisation
|
||||
@ -27,7 +28,7 @@ class LokiMultiDeviceDatabase(context: Context, helper: SQLCipherOpenHelper) : D
|
||||
");"
|
||||
}
|
||||
|
||||
fun insertOrUpdatePairingAuthorisation(authorisation: LokiPairingAuthorisation) {
|
||||
override fun insertOrUpdatePairingAuthorisation(authorisation: LokiPairingAuthorisation) {
|
||||
val database = databaseHelper.writableDatabase
|
||||
val values = ContentValues()
|
||||
values.put(primaryDevice, authorisation.primaryDevicePubKey)
|
||||
@ -37,6 +38,11 @@ class LokiMultiDeviceDatabase(context: Context, helper: SQLCipherOpenHelper) : D
|
||||
database.insertOrUpdate(authorisation_table, values, "$primaryDevice = ? AND $secondaryDevice = ?", arrayOf(authorisation.primaryDevicePubKey, authorisation.secondaryDevicePubKey))
|
||||
}
|
||||
|
||||
override fun removePairingAuthorisations(pubKey: String) {
|
||||
val database = databaseHelper.readableDatabase
|
||||
database.delete(authorisation_table, "$primaryDevice = ? OR $secondaryDevice = ?", arrayOf(pubKey, pubKey))
|
||||
}
|
||||
|
||||
fun getAuthorisationForSecondaryDevice(pubKey: String): LokiPairingAuthorisation? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(authorisation_table, "$secondaryDevice = ?", arrayOf(pubKey)) { cursor ->
|
||||
@ -48,7 +54,7 @@ class LokiMultiDeviceDatabase(context: Context, helper: SQLCipherOpenHelper) : D
|
||||
}
|
||||
}
|
||||
|
||||
fun getSecondaryDevices(primaryDevicePubKey: String): List<String> {
|
||||
override fun getSecondaryDevices(primaryDevicePubKey: String): List<String> {
|
||||
val database = databaseHelper.readableDatabase
|
||||
|
||||
var cursor: Cursor? = null
|
||||
@ -68,7 +74,7 @@ class LokiMultiDeviceDatabase(context: Context, helper: SQLCipherOpenHelper) : D
|
||||
return results
|
||||
}
|
||||
|
||||
fun getPrimaryDevice(secondaryDevicePubKey: String): String? {
|
||||
override fun getPrimaryDevice(secondaryDevicePubKey: String): String? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(authorisation_table, "$secondaryDevice = ?", arrayOf(secondaryDevicePubKey)) { cursor ->
|
||||
cursor.getString(primaryDevice)
|
||||
|
Loading…
x
Reference in New Issue
Block a user