2020-05-12 11:46:11 +10:00
|
|
|
package org.thoughtcrime.securesms.loki.protocol
|
2020-02-14 11:18:23 +11:00
|
|
|
|
|
|
|
import android.content.Context
|
2020-05-13 12:29:31 +10:00
|
|
|
import org.thoughtcrime.securesms.ApplicationContext
|
2020-02-14 11:18:23 +11:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
2020-07-15 12:24:43 +10:00
|
|
|
import org.whispersystems.libsignal.loki.SessionResetProtocol
|
|
|
|
import org.whispersystems.libsignal.loki.SessionResetStatus
|
2020-02-14 11:18:23 +11:00
|
|
|
import org.whispersystems.libsignal.protocol.PreKeySignalMessage
|
|
|
|
|
2020-07-15 14:26:20 +10:00
|
|
|
class SessionResetImplementation(private val context: Context) : SessionResetProtocol {
|
2020-02-14 11:18:23 +11:00
|
|
|
|
2020-07-15 12:24:43 +10:00
|
|
|
override fun getSessionResetStatus(publicKey: String): SessionResetStatus {
|
|
|
|
return DatabaseFactory.getLokiThreadDatabase(context).getSessionResetStatus(publicKey)
|
2020-05-13 10:24:20 +10:00
|
|
|
}
|
2020-02-14 11:18:23 +11:00
|
|
|
|
2020-07-15 12:24:43 +10:00
|
|
|
override fun setSessionResetStatus(publicKey: String, sessionResetStatus: SessionResetStatus) {
|
|
|
|
return DatabaseFactory.getLokiThreadDatabase(context).setSessionResetStatus(publicKey, sessionResetStatus)
|
2020-02-14 11:18:23 +11:00
|
|
|
}
|
|
|
|
|
2020-07-15 12:24:43 +10:00
|
|
|
override fun onNewSessionAdopted(publicKey: String, oldSessionResetStatus: SessionResetStatus) {
|
|
|
|
if (oldSessionResetStatus == SessionResetStatus.IN_PROGRESS) {
|
2020-07-15 15:14:37 +10:00
|
|
|
val job = PushNullMessageSendJob(publicKey)
|
|
|
|
ApplicationContext.getInstance(context).jobManager.add(job)
|
2020-05-13 10:24:20 +10:00
|
|
|
}
|
|
|
|
// TODO: Show session reset succeed message
|
|
|
|
}
|
2020-02-14 11:18:23 +11:00
|
|
|
|
2020-07-15 12:24:43 +10:00
|
|
|
override fun validatePreKeySignalMessage(publicKey: String, message: PreKeySignalMessage) {
|
|
|
|
val preKeyRecord = DatabaseFactory.getLokiPreKeyRecordDatabase(context).getPreKeyRecord(publicKey) ?: return
|
2020-06-01 16:38:28 +10:00
|
|
|
// TODO: Checking that the pre key record isn't null is causing issues when it shouldn't
|
2020-05-13 10:24:20 +10:00
|
|
|
check(preKeyRecord.id == (message.preKeyId ?: -1)) { "Received a background message from an unknown source." }
|
|
|
|
}
|
2020-02-14 11:18:23 +11:00
|
|
|
}
|