Add internal tool to reset sender key state.

This commit is contained in:
Greyson Parrelli
2025-06-26 13:32:00 -04:00
committed by Cody Henthorne
parent 0f16be81b0
commit fdd9e07918
2 changed files with 39 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update import kotlinx.coroutines.flow.update
import org.signal.core.util.concurrent.SignalExecutors import org.signal.core.util.concurrent.SignalExecutors
import org.signal.core.util.isAbsent import org.signal.core.util.isAbsent
import org.signal.core.util.logging.Log
import org.signal.core.util.orNull import org.signal.core.util.orNull
import org.signal.core.util.roundedString import org.signal.core.util.roundedString
import org.signal.core.util.withinTransaction import org.signal.core.util.withinTransaction
@@ -47,6 +48,10 @@ import kotlin.time.DurationUnit
@Stable @Stable
class InternalConversationSettingsFragment : ComposeFragment(), InternalConversationSettingsScreenCallbacks { class InternalConversationSettingsFragment : ComposeFragment(), InternalConversationSettingsScreenCallbacks {
companion object {
val TAG = Log.tag(InternalConversationSettingsFragment::class.java)
}
private val viewModel: InternalViewModel by viewModels( private val viewModel: InternalViewModel by viewModels(
factoryProducer = { factoryProducer = {
val recipientId = InternalConversationSettingsFragmentArgs.fromBundle(requireArguments()).recipientId val recipientId = InternalConversationSettingsFragmentArgs.fromBundle(requireArguments()).recipientId
@@ -250,6 +255,21 @@ class InternalConversationSettingsFragment : ComposeFragment(), InternalConversa
Toast.makeText(context, "Done! Split the ACI and profile key off into $aciRecipientId", Toast.LENGTH_SHORT).show() Toast.makeText(context, "Done! Split the ACI and profile key off into $aciRecipientId", Toast.LENGTH_SHORT).show()
} }
override fun clearSenderKey(recipientId: RecipientId) {
val group = SignalDatabase.groups.getGroup(recipientId).orNull()
if (group == null) {
Log.w(TAG, "Couldn't find group for recipientId: $recipientId")
return
}
if (group.distributionId == null) {
Log.w(TAG, "No distributionId for recipientId: $recipientId")
return
}
SignalDatabase.senderKeyShared.deleteAllFor(group.distributionId)
}
class InternalViewModel( class InternalViewModel(
val recipientId: RecipientId val recipientId: RecipientId
) : ViewModel(), RecipientForeverObserver { ) : ViewModel(), RecipientForeverObserver {

View File

@@ -33,6 +33,7 @@ import org.thoughtcrime.securesms.recipients.RecipientId
private enum class Dialog { private enum class Dialog {
NONE, NONE,
DISABLE_PROFILE_SHARING, DISABLE_PROFILE_SHARING,
CLEAR_SENDER_KEY,
DELETE_SESSIONS, DELETE_SESSIONS,
ARCHIVE_SESSIONS, ARCHIVE_SESSIONS,
DELETE_AVATAR, DELETE_AVATAR,
@@ -193,11 +194,21 @@ fun InternalConversationSettingsScreen(
) )
} }
if (!state.isGroup) {
item { item {
Texts.SectionHeader(text = "Actions") Texts.SectionHeader(text = "Actions")
} }
if (state.isGroup) {
item {
Rows.TextRow(
text = "Clear sender key",
label = "Resets any sender key state, meaning the next message will require re-distributing sender key material.",
onClick = {
dialog = Dialog.CLEAR_SENDER_KEY
}
)
}
} else {
item { item {
Rows.TextRow( Rows.TextRow(
text = "Disable Profile Sharing", text = "Disable Profile Sharing",
@@ -362,6 +373,9 @@ private fun rememberOnConfirm(
Dialog.SPLIT_WITHOUT_CREATING_THREADS -> { Dialog.SPLIT_WITHOUT_CREATING_THREADS -> {
{ callbacks.splitWithoutCreatingThreads(state.recipientId) } { callbacks.splitWithoutCreatingThreads(state.recipientId) }
} }
Dialog.CLEAR_SENDER_KEY -> {
{ callbacks.clearSenderKey(state.recipientId) }
}
} }
} }
} }
@@ -459,6 +473,7 @@ interface InternalConversationSettingsScreenCallbacks {
fun add10Messages(recipientId: RecipientId) = Unit fun add10Messages(recipientId: RecipientId) = Unit
fun splitAndCreateThreads(recipientId: RecipientId) = Unit fun splitAndCreateThreads(recipientId: RecipientId) = Unit
fun splitWithoutCreatingThreads(recipientId: RecipientId) = Unit fun splitWithoutCreatingThreads(recipientId: RecipientId) = Unit
fun clearSenderKey(recipientId: RecipientId) = Unit
object Empty : InternalConversationSettingsScreenCallbacks object Empty : InternalConversationSettingsScreenCallbacks
} }