From 7eb089c9def88279e1012a246e3de20d8d3a133f Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Sat, 25 Nov 2017 09:50:36 -0800 Subject: [PATCH] Temporary fix for Signal contact displaying as SMS for N seconds The whole recipient pipeline needs to be changed more subsantially, particularly given the way directory discovery works with it. This will temporarily solve the problem though. --- .../thoughtcrime/securesms/ConversationActivity.java | 11 ++++++++++- .../securesms/database/RecipientDatabase.java | 10 ++++++++++ .../thoughtcrime/securesms/recipients/Recipient.java | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 83c5056e1a..298855f28c 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -1053,7 +1053,16 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity Context context = ConversationActivity.this; Recipient recipient = params[0]; Log.w(TAG, "Resolving registered state..."); - RegisteredState registeredState = recipient.resolve().getRegistered(); + RegisteredState registeredState; + + if (recipient.isResolving()) { + Log.w(TAG, "Talking to DB directly."); + registeredState = DatabaseFactory.getRecipientDatabase(ConversationActivity.this).isRegistered(recipient.getAddress()); + } else { + Log.w(TAG, "Checking through resolved recipient"); + registeredState = recipient.resolve().getRegistered(); + } + Log.w(TAG, "Resolved registered state: " + registeredState); boolean signalEnabled = TextSecurePreferences.isPushRegistered(context); diff --git a/src/org/thoughtcrime/securesms/database/RecipientDatabase.java b/src/org/thoughtcrime/securesms/database/RecipientDatabase.java index 1926d6a156..9ccaf34874 100644 --- a/src/org/thoughtcrime/securesms/database/RecipientDatabase.java +++ b/src/org/thoughtcrime/securesms/database/RecipientDatabase.java @@ -345,6 +345,16 @@ public class RecipientDatabase extends Database { return results; } + // XXX This shouldn't be here, and is just a temporary workaround + public RegisteredState isRegistered(@NonNull Address address) { + SQLiteDatabase db = databaseHelper.getReadableDatabase(); + + try (Cursor cursor = db.query(TABLE_NAME, new String[] {REGISTERED}, ADDRESS + " = ?", new String[] {address.serialize()}, null, null, null)) { + if (cursor != null && cursor.moveToFirst()) return RegisteredState.fromId(cursor.getInt(0)); + else return RegisteredState.UNKNOWN; + } + } + private void updateOrInsert(Address address, ContentValues contentValues) { SQLiteDatabase database = databaseHelper.getWritableDatabase(); diff --git a/src/org/thoughtcrime/securesms/recipients/Recipient.java b/src/org/thoughtcrime/securesms/recipients/Recipient.java index d2bb6c729e..f4a8628cf8 100644 --- a/src/org/thoughtcrime/securesms/recipients/Recipient.java +++ b/src/org/thoughtcrime/securesms/recipients/Recipient.java @@ -529,7 +529,8 @@ public class Recipient implements RecipientModifiedListener { this.stale = true; } - synchronized boolean isResolving() { + // XXX This shouldn't be public, temporary workaround + public synchronized boolean isResolving() { return resolving; }