From 3c4e3cf0481edf5ac07b464d2958b377025c1dbb Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 24 Aug 2021 15:15:41 -0400 Subject: [PATCH] Improve retrieval from the identity table. --- .../securesms/database/IdentityDatabase.java | 15 +++++++++++++++ .../database/helpers/SQLCipherOpenHelper.java | 14 +++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/IdentityDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/IdentityDatabase.java index 9b22702b99..01ddf50e07 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/IdentityDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/IdentityDatabase.java @@ -147,6 +147,21 @@ public class IdentityDatabase extends Database { firstUse, timestamp, nonblockingApproval); + } else if (addressName.charAt(0) != '+') { + if (DatabaseFactory.getRecipientDatabase(context).containsPhoneOrUuid(addressName)) { + Recipient recipient = Recipient.external(context, addressName); + + if (recipient.hasE164()) { + Log.i(TAG, "Could not find identity for UUID. Attempting E164."); + return getIdentityStoreRecord(recipient.requireE164()); + } else { + Log.i(TAG, "Could not find identity for UUID, and our recipient doesn't have an E164."); + } + } else { + Log.i(TAG, "Could not find identity for UUID, and we don't have a recipient."); + } + } else { + Log.i(TAG, "Could not find identity for E164 either."); } } catch (InvalidKeyException | IOException e) { throw new AssertionError(e); diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java index d468c5de4f..c054639bae 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java @@ -214,8 +214,9 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper implements SignalDatab private static final int SESSION_MIGRATION = 113; private static final int IDENTITY_MIGRATION = 114; private static final int GROUP_CALL_RING_TABLE = 115; + private static final int CLEANUP_SESSION_MIGRATION = 116; - private static final int DATABASE_VERSION = 115; + private static final int DATABASE_VERSION = 116; private static final String DATABASE_NAME = "signal.db"; private final Context context; @@ -2025,6 +2026,17 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper implements SignalDatab db.execSQL("CREATE INDEX date_received_index on group_call_ring (date_received)"); } + if (oldVersion < CLEANUP_SESSION_MIGRATION) { + int sessionCount = db.delete("sessions", "address LIKE '+%'", null); + Log.i(TAG, "Cleaned up " + sessionCount + " sessions."); + + ContentValues storageValues = new ContentValues(); + storageValues.putNull("storage_service_key"); + + int storageCount = db.update("recipient", storageValues, "storage_service_key NOT NULL AND group_id IS NULL AND uuid IS NULL", null); + Log.i(TAG, "Cleaned up " + storageCount + " storageIds."); + } + db.setTransactionSuccessful(); } finally { db.endTransaction();