mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 21:12:20 +00:00
Refactor
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user