diff --git a/src/org/thoughtcrime/securesms/loki/dialogs/ClearAllDataDialog.kt b/src/org/thoughtcrime/securesms/loki/dialogs/ClearAllDataDialog.kt index 42e4e0711a..50e54567b9 100644 --- a/src/org/thoughtcrime/securesms/loki/dialogs/ClearAllDataDialog.kt +++ b/src/org/thoughtcrime/securesms/loki/dialogs/ClearAllDataDialog.kt @@ -10,12 +10,13 @@ import android.view.LayoutInflater import kotlinx.android.synthetic.main.dialog_clear_all_data.view.* import network.loki.messenger.R import org.thoughtcrime.securesms.ApplicationContext +import org.thoughtcrime.securesms.loki.utilities.KeyPairUtilities class ClearAllDataDialog : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val builder = AlertDialog.Builder(context!!) - val contentView = LayoutInflater.from(context!!).inflate(R.layout.dialog_clear_all_data, null) + val builder = AlertDialog.Builder(requireContext()) + val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_clear_all_data, null) contentView.cancelButton.setOnClickListener { dismiss() } contentView.clearAllDataButton.setOnClickListener { clearAllData() } builder.setView(contentView) @@ -25,6 +26,19 @@ class ClearAllDataDialog : DialogFragment() { } private fun clearAllData() { - ApplicationContext.getInstance(context).clearData() + if (KeyPairUtilities.hasV2KeyPair(requireContext())) { + ApplicationContext.getInstance(context).clearData() + } else { + val dialog = AlertDialog.Builder(requireContext()) + val message = "We’ve upgraded the way Session IDs are generated, so you will be unable to restore your current Session ID." + dialog.setMessage(message) + dialog.setPositiveButton("Yes") { _, _ -> + ApplicationContext.getInstance(context).clearData() + } + dialog.setNegativeButton("Cancel") { _, _ -> + // Do nothing + } + dialog.create().show() + } } } \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/utilities/KeyPairUtilities.kt b/src/org/thoughtcrime/securesms/loki/utilities/KeyPairUtilities.kt index 0f8cc44c33..31038c251f 100644 --- a/src/org/thoughtcrime/securesms/loki/utilities/KeyPairUtilities.kt +++ b/src/org/thoughtcrime/securesms/loki/utilities/KeyPairUtilities.kt @@ -45,4 +45,8 @@ object KeyPairUtilities { IdentityKeyUtil.save(context, IdentityKeyUtil.ED25519_PUBLIC_KEY, Base64.encodeBytes(ed25519KeyPair.publicKey.asBytes)) IdentityKeyUtil.save(context, IdentityKeyUtil.ED25519_SECRET_KEY, Base64.encodeBytes(ed25519KeyPair.secretKey.asBytes)) } + + fun hasV2KeyPair(context: Context): Boolean { + return (IdentityKeyUtil.retrieve(context, IdentityKeyUtil.ED25519_SECRET_KEY) != null) + } } \ No newline at end of file