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 62cae4deb..3ed46ffd7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java @@ -648,13 +648,18 @@ 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()); + 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(); + + if (!update.getProfileKey().isPresent()) { + Log.w(TAG, "Got an empty profile key while applying an account record update!"); + } values.put(PROFILE_GIVEN_NAME, profileName.getGivenName()); values.put(PROFILE_FAMILY_NAME, profileName.getFamilyName()); values.put(PROFILE_JOINED_NAME, profileName.toString()); - values.put(PROFILE_KEY, update.getProfileKey().transform(Base64::encodeBytes).orNull()); + values.put(PROFILE_KEY, profileKey); values.put(STORAGE_SERVICE_ID, Base64.encodeBytes(update.getId().getRaw())); values.put(DIRTY, DirtyState.CLEAN.getId()); diff --git a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncHelper.java b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncHelper.java index c66b218d2..3196224a2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncHelper.java +++ b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncHelper.java @@ -385,7 +385,6 @@ public final class StorageSyncHelper { } public static SignalStorageRecord buildAccountRecord(@NonNull Context context, @NonNull Recipient self) { - SignalAccountRecord account = new SignalAccountRecord.Builder(self.getStorageServiceId()) .setProfileKey(self.getProfileKey()) .setGivenName(self.getProfileName().getGivenName())