From 5468f1705c2f7cdd134124e36babf9f0d252b327 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Thu, 16 Jul 2020 09:33:47 -0400 Subject: [PATCH] Ensure we refresh attributes if key changes from storage service. --- .../securesms/database/RecipientDatabase.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java index f39a254bbe..2a1bd7835a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java @@ -28,6 +28,7 @@ import org.thoughtcrime.securesms.database.model.ThreadRecord; import org.thoughtcrime.securesms.dependencies.ApplicationDependencies; import org.thoughtcrime.securesms.groups.GroupId; import org.thoughtcrime.securesms.groups.v2.ProfileKeySet; +import org.thoughtcrime.securesms.jobs.RefreshAttributesJob; import org.thoughtcrime.securesms.jobs.WakeGroupV2Job; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.profiles.AvatarHelper; @@ -54,6 +55,7 @@ import org.whispersystems.signalservice.api.storage.SignalContactRecord; import org.whispersystems.signalservice.api.storage.SignalGroupV1Record; import org.whispersystems.signalservice.api.storage.SignalGroupV2Record; import org.whispersystems.signalservice.api.storage.StorageId; +import org.whispersystems.signalservice.api.util.OptionalUtil; import org.whispersystems.signalservice.api.util.UuidUtil; import java.io.Closeable; @@ -850,11 +852,13 @@ public class RecipientDatabase extends Database { public void applyStorageSyncUpdates(@NonNull StorageId storageId, SignalAccountRecord update) { SQLiteDatabase db = databaseHelper.getWritableDatabase(); - ContentValues values = new ContentValues(); - ProfileName profileName = ProfileName.fromParts(update.getGivenName().orNull(), update.getFamilyName().orNull()); - String profileKey = update.getProfileKey().or(Optional.fromNullable(Recipient.self().getProfileKey())).transform(Base64::encodeBytes).orNull(); + ContentValues values = new ContentValues(); + ProfileName profileName = ProfileName.fromParts(update.getGivenName().orNull(), update.getFamilyName().orNull()); + Optional localKey = ProfileKeyUtil.profileKeyOptional(Recipient.self().getProfileKey()); + Optional remoteKey = ProfileKeyUtil.profileKeyOptional(update.getProfileKey().orNull()); + String profileKey = remoteKey.or(localKey).transform(ProfileKey::serialize).transform(Base64::encodeBytes).orNull(); - if (!update.getProfileKey().isPresent()) { + if (!remoteKey.isPresent()) { Log.w(TAG, "Got an empty profile key while applying an account record update!"); } @@ -870,6 +874,10 @@ public class RecipientDatabase extends Database { throw new AssertionError("Account update didn't match any rows!"); } + if (!remoteKey.equals(localKey)) { + ApplicationDependencies.getJobManager().add(new RefreshAttributesJob()); + } + Recipient.self().live().refresh(); }