Fix storage service crash when matching a local contact without an ID.

It's possible that we could match a local contact that doesn't have a
storageId, which would crash when we tried to make a model from it for
merging. This isn't an impossible case -- it could be that the manifest
has record of a user that is newly registered (or just registered at
some point and never deleted) and so we need to give our local record a
storageId for merging.
This commit is contained in:
Greyson Parrelli
2021-04-15 09:38:30 -04:00
parent 69ebee3eeb
commit 60690208de
8 changed files with 24 additions and 24 deletions

View File

@@ -2716,12 +2716,16 @@ public class RecipientDatabase extends Database {
ApplicationDependencies.getRecipientCache().clear();
}
public void updateStorageKeys(@NonNull Map<RecipientId, byte[]> keys) {
public void updateStorageId(@NonNull RecipientId recipientId, byte[] id) {
updateStorageIds(Collections.singletonMap(recipientId, id));
}
public void updateStorageIds(@NonNull Map<RecipientId, byte[]> ids) {
SQLiteDatabase db = databaseHelper.getWritableDatabase();
db.beginTransaction();
try {
for (Map.Entry<RecipientId, byte[]> entry : keys.entrySet()) {
for (Map.Entry<RecipientId, byte[]> entry : ids.entrySet()) {
ContentValues values = new ContentValues();
values.put(STORAGE_SERVICE_ID, Base64.encodeBytes(entry.getValue()));
db.update(TABLE_NAME, values, ID_WHERE, new String[] { entry.getKey().serialize() });
@@ -2732,7 +2736,7 @@ public class RecipientDatabase extends Database {
db.endTransaction();
}
for (RecipientId id : keys.keySet()) {
for (RecipientId id : ids.keySet()) {
Recipient.live(id).refresh();
}
}