mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 00:03:54 +00:00
Refactor
This commit is contained in:
parent
06e8d20da4
commit
9be8d75773
@ -10,11 +10,11 @@ import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.whispersystems.libsignal.SignalProtocolAddress;
|
||||
import org.whispersystems.libsignal.protocol.CiphertextMessage;
|
||||
import org.whispersystems.libsignal.state.SessionRecord;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiSessionProtocol;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiSessionDatabaseProtocol;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TextSecureSessionStore implements LokiSessionProtocol {
|
||||
public class TextSecureSessionStore implements LokiSessionDatabaseProtocol {
|
||||
|
||||
private static final String TAG = TextSecureSessionStore.class.getSimpleName();
|
||||
|
||||
|
@ -87,7 +87,6 @@ import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.IdentityUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libsignal.state.PreKeyBundle;
|
||||
import org.whispersystems.libsignal.state.SessionStore;
|
||||
import org.whispersystems.libsignal.state.SignalProtocolStore;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
|
||||
@ -115,10 +114,8 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.loki.crypto.LokiServiceCipher;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiServiceMessage;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiThreadDatabaseProtocol;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiPreKeyRecordDatabaseProtocol;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiThreadSessionResetState;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiThreadSessionResetStatus;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
@ -477,7 +474,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
// sessionStore.deleteAllSessions(content.getSender());
|
||||
|
||||
sessionStore.archiveAllSessions(content.getSender());
|
||||
lokiThreadDatabase.setSessionResetState(threadId, LokiThreadSessionResetState.REQUEST_RECEIVED);
|
||||
lokiThreadDatabase.setSessionResetStatus(threadId, LokiThreadSessionResetStatus.REQUEST_RECEIVED);
|
||||
|
||||
// TODO: Send a background message here
|
||||
Log.d("Loki", "Received a session reset request from: " + content.getSender() + ".");
|
||||
|
@ -43,7 +43,7 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
||||
TextSecurePreferences.setLocalRegistrationId(context, registrationID)
|
||||
}
|
||||
val deviceID = SignalServiceAddress.DEFAULT_DEVICE_ID
|
||||
val preKeyRecord = DatabaseFactory.getLokiPreKeyRecordDatabase(context).getOrCreatePreKey(hexEncodedPublicKey)
|
||||
val preKeyRecord = DatabaseFactory.getLokiPreKeyRecordDatabase(context).getOrCreatePreKeyRecord(hexEncodedPublicKey)
|
||||
val identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context)
|
||||
if (TextSecurePreferences.isSignedPreKeyRegistered(context)) {
|
||||
Log.d("Loki", "A signed pre key has already been registered.")
|
||||
|
@ -23,7 +23,7 @@ class LokiPreKeyRecordDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
||||
return database.get(tableName, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey )) { it.count > 0 } ?: false
|
||||
}
|
||||
|
||||
override fun getPreKey(hexEncodedPublicKey: String): PreKeyRecord? {
|
||||
override fun getPreKeyRecord(hexEncodedPublicKey: String): PreKeyRecord? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(tableName, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey )) { cursor ->
|
||||
val preKeyID = cursor.getInt(preKeyID)
|
||||
@ -31,11 +31,11 @@ class LokiPreKeyRecordDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
||||
}
|
||||
}
|
||||
|
||||
fun getOrCreatePreKey(hexEncodedPublicKey: String): PreKeyRecord {
|
||||
return getPreKey(hexEncodedPublicKey) ?: generateAndStorePreKey(hexEncodedPublicKey)
|
||||
fun getOrCreatePreKeyRecord(hexEncodedPublicKey: String): PreKeyRecord {
|
||||
return getPreKeyRecord(hexEncodedPublicKey) ?: generateAndStorePreKeyRecord(hexEncodedPublicKey)
|
||||
}
|
||||
|
||||
private fun generateAndStorePreKey(hexEncodedPublicKey: String): PreKeyRecord {
|
||||
private fun generateAndStorePreKeyRecord(hexEncodedPublicKey: String): PreKeyRecord {
|
||||
val preKeyRecords = PreKeyUtil.generatePreKeys(context, 1)
|
||||
PreKeyUtil.storePreKeyRecords(context, preKeyRecords)
|
||||
val record = preKeyRecords.first()
|
||||
|
@ -9,7 +9,7 @@ import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiThreadDatabaseProtocol
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiThreadSessionResetState
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiThreadSessionResetStatus
|
||||
|
||||
class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiThreadDatabaseProtocol {
|
||||
var delegate: LokiThreadDatabaseDelegate? = null
|
||||
@ -63,19 +63,19 @@ class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa
|
||||
|| friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_RECEIVED
|
||||
}
|
||||
|
||||
override fun getSessionResetState(threadID: Long): LokiThreadSessionResetState {
|
||||
override fun getSessionResetStatus(threadID: Long): LokiThreadSessionResetStatus {
|
||||
val database = databaseHelper.readableDatabase
|
||||
val result = database.get(sessionResetTableName, "${Companion.threadID} = ?", arrayOf( threadID.toString() )) { cursor ->
|
||||
cursor.getInt(sessionResetStatus)
|
||||
}
|
||||
return if (result != null) {
|
||||
LokiThreadSessionResetState.values().first { it.rawValue == result }
|
||||
LokiThreadSessionResetStatus.values().first { it.rawValue == result }
|
||||
} else {
|
||||
LokiThreadSessionResetState.NONE
|
||||
LokiThreadSessionResetStatus.NONE
|
||||
}
|
||||
}
|
||||
|
||||
override fun setSessionResetState(threadID: Long, sessionResetStatus: LokiThreadSessionResetState) {
|
||||
override fun setSessionResetStatus(threadID: Long, sessionResetStatus: LokiThreadSessionResetStatus) {
|
||||
val database = databaseHelper.writableDatabase
|
||||
val contentValues = ContentValues(2)
|
||||
contentValues.put(Companion.threadID, threadID)
|
||||
|
Loading…
x
Reference in New Issue
Block a user