mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 14:38:33 +00:00
Fix storage service crash with new users.
This commit is contained in:
parent
d507be0ab0
commit
9c96afee09
@ -456,24 +456,38 @@ public class RecipientDatabase extends Database {
|
|||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
for (SignalContactRecord insert : contactInserts) {
|
for (SignalContactRecord insert : contactInserts) {
|
||||||
ContentValues values = getValuesForStorageContact(insert);
|
ContentValues values = getValuesForStorageContact(insert);
|
||||||
long id = db.insertOrThrow(TABLE_NAME, null, values);
|
long id = db.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_IGNORE);
|
||||||
RecipientId recipientId = RecipientId.from(id);
|
|
||||||
|
|
||||||
if (insert.getIdentityKey().isPresent()) {
|
if (id < 0) {
|
||||||
try {
|
Log.w(TAG, "Failed to insert! It's likely that these were newly-registered users that were missed in the merge. Doing an update instead.");
|
||||||
IdentityKey identityKey = new IdentityKey(insert.getIdentityKey().get(), 0);
|
|
||||||
|
|
||||||
DatabaseFactory.getIdentityDatabase(context).updateIdentityAfterSync(recipientId, identityKey, StorageSyncHelper.remoteToLocalIdentityStatus(insert.getIdentityState()));
|
if (insert.getAddress().getNumber().isPresent()) {
|
||||||
IdentityUtil.markIdentityVerified(context, Recipient.resolved(recipientId), true, true);
|
int count = db.update(TABLE_NAME, values, PHONE + " = ?", new String[] { insert.getAddress().getNumber().get() });
|
||||||
} catch (InvalidKeyException e) {
|
Log.w(TAG, "Updated " + count + " users by E164.");
|
||||||
Log.w(TAG, "Failed to process identity key during insert! Skipping.", e);
|
} else {
|
||||||
|
int count = db.update(TABLE_NAME, values, UUID + " = ?", new String[] { insert.getAddress().getUuid().get().toString() });
|
||||||
|
Log.w(TAG, "Updated " + count + " users by UUID.");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
RecipientId recipientId = RecipientId.from(id);
|
||||||
|
|
||||||
if (Recipient.self().getId().equals(recipientId)) {
|
if (insert.getIdentityKey().isPresent()) {
|
||||||
TextSecurePreferences.setProfileName(context, ProfileName.fromParts(insert.getGivenName().orNull(), insert.getFamilyName().orNull()));
|
try {
|
||||||
|
IdentityKey identityKey = new IdentityKey(insert.getIdentityKey().get(), 0);
|
||||||
|
|
||||||
|
DatabaseFactory.getIdentityDatabase(context).updateIdentityAfterSync(recipientId, identityKey, StorageSyncHelper.remoteToLocalIdentityStatus(insert.getIdentityState()));
|
||||||
|
IdentityUtil.markIdentityVerified(context, Recipient.resolved(recipientId), true, true);
|
||||||
|
} catch (InvalidKeyException e) {
|
||||||
|
Log.w(TAG, "Failed to process identity key during insert! Skipping.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Recipient.self().getId().equals(recipientId)) {
|
||||||
|
TextSecurePreferences.setProfileName(context, ProfileName.fromParts(insert.getGivenName().orNull(), insert.getFamilyName().orNull()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user