From 97d95f37cca88126842b2256f37da714b33abb64 Mon Sep 17 00:00:00 2001 From: Clark Date: Mon, 22 May 2023 12:34:19 -0400 Subject: [PATCH] Rotate profile key when contact hidden. --- .../management/ContactsManagementRepository.kt | 8 +++++++- .../securesms/database/RecipientTable.kt | 18 +++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/management/ContactsManagementRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/contacts/management/ContactsManagementRepository.kt index d187424853..813f69b4de 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/management/ContactsManagementRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/management/ContactsManagementRepository.kt @@ -5,6 +5,8 @@ import androidx.annotation.CheckResult import io.reactivex.rxjava3.core.Completable import io.reactivex.rxjava3.schedulers.Schedulers import org.thoughtcrime.securesms.database.SignalDatabase +import org.thoughtcrime.securesms.dependencies.ApplicationDependencies +import org.thoughtcrime.securesms.jobs.RotateProfileKeyJob import org.thoughtcrime.securesms.recipients.Recipient import org.thoughtcrime.securesms.recipients.RecipientUtil @@ -31,7 +33,11 @@ class ContactsManagementRepository(context: Context) { error("Cannot hide groups, self, or distribution lists.") } - SignalDatabase.recipients.markHidden(recipient.id) + val rotateProfileKey = !recipient.hasGroupsInCommon() + SignalDatabase.recipients.markHidden(recipient.id, rotateProfileKey) + if (rotateProfileKey) { + ApplicationDependencies.getJobManager().add(RotateProfileKeyJob()) + } } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientTable.kt b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientTable.kt index 9b04c06ac0..8b0115dd1d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientTable.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientTable.kt @@ -1806,11 +1806,19 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da } } - fun markHidden(id: RecipientId) { - val contentValues = contentValuesOf( - HIDDEN to 1, - PROFILE_SHARING to 0 - ) + fun markHidden(id: RecipientId, clearProfileKey: Boolean = false) { + val contentValues = if (clearProfileKey) { + contentValuesOf( + HIDDEN to 1, + PROFILE_SHARING to 0, + PROFILE_KEY to null + ) + } else { + contentValuesOf( + HIDDEN to 1, + PROFILE_SHARING to 0 + ) + } val updated = writableDatabase.update(TABLE_NAME, contentValues, "$ID_WHERE AND $GROUP_TYPE = ?", SqlUtil.buildArgs(id, GroupType.NONE.id)) > 0 if (updated) {