diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 12ffff669e..ae3f1d88b1 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -143,8 +143,7 @@ import org.thoughtcrime.securesms.sms.OutgoingTextMessage; import org.thoughtcrime.securesms.util.CharacterCalculator.CharacterState; import org.thoughtcrime.securesms.util.Dialogs; import org.thoughtcrime.securesms.util.DirectoryHelper; -import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities; -import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities.Capability; +import org.thoughtcrime.securesms.util.DirectoryHelper.Capability; import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.DynamicTheme; import org.thoughtcrime.securesms.util.ExpirationUtil; @@ -1016,19 +1015,17 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity protected boolean[] doInBackground(Recipient... params) { Context context = ConversationActivity.this; Recipient recipient = params[0]; - UserCapabilities capabilities = DirectoryHelper.getUserCapabilities(context, recipient); + Capability capability = DirectoryHelper.getUserCapabilities(context, recipient); - if (capabilities.getTextCapability() == Capability.UNKNOWN || - capabilities.getVideoCapability() == Capability.UNKNOWN) - { + if (capability == Capability.UNKNOWN) { try { - capabilities = DirectoryHelper.refreshDirectoryFor(context, masterSecret, recipient); + capability = DirectoryHelper.refreshDirectoryFor(context, masterSecret, recipient); } catch (IOException e) { Log.w(TAG, e); } } - return new boolean[] {capabilities.getTextCapability() == Capability.SUPPORTED, Util.isDefaultSmsProvider(context)}; + return new boolean[] {capability == Capability.SUPPORTED, Util.isDefaultSmsProvider(context)}; } @Override diff --git a/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java b/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java index 1459e53f8a..d5f878ffbf 100644 --- a/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java +++ b/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java @@ -407,9 +407,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi DatabaseFactory.getRecipientPreferenceDatabase(context) .setColor(recipient, selectedColor); - if (DirectoryHelper.getUserCapabilities(context, recipient) - .getTextCapability() == DirectoryHelper.UserCapabilities.Capability.SUPPORTED) - { + if (DirectoryHelper.getUserCapabilities(context, recipient) == DirectoryHelper.Capability.SUPPORTED) { ApplicationContext.getInstance(context) .getJobManager() .add(new MultiDeviceContactUpdateJob(context, recipient.getAddress())); diff --git a/src/org/thoughtcrime/securesms/contacts/ContactsCursorLoader.java b/src/org/thoughtcrime/securesms/contacts/ContactsCursorLoader.java index 3329c87220..c73c50c32a 100644 --- a/src/org/thoughtcrime/securesms/contacts/ContactsCursorLoader.java +++ b/src/org/thoughtcrime/securesms/contacts/ContactsCursorLoader.java @@ -32,7 +32,6 @@ import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.RecipientFactory; import org.thoughtcrime.securesms.util.DirectoryHelper; -import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities.Capability; import org.thoughtcrime.securesms.util.NumberUtil; import java.util.ArrayList; @@ -106,7 +105,7 @@ public class ContactsCursorLoader extends CursorLoader { final String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_COLUMN)); final Recipient recipient = RecipientFactory.getRecipientFor(getContext(), Address.fromExternal(getContext(), number), true); - if (DirectoryHelper.getUserCapabilities(getContext(), recipient).getTextCapability() != Capability.SUPPORTED) { + if (DirectoryHelper.getUserCapabilities(getContext(), recipient) != DirectoryHelper.Capability.SUPPORTED) { matrix.addRow(new Object[]{cursor.getLong(cursor.getColumnIndexOrThrow(ContactsDatabase.ID_COLUMN)), cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NAME_COLUMN)), number, diff --git a/src/org/thoughtcrime/securesms/util/DirectoryHelper.java b/src/org/thoughtcrime/securesms/util/DirectoryHelper.java index 4eba1e216e..b5e0248483 100644 --- a/src/org/thoughtcrime/securesms/util/DirectoryHelper.java +++ b/src/org/thoughtcrime/securesms/util/DirectoryHelper.java @@ -30,7 +30,6 @@ import org.thoughtcrime.securesms.notifications.MessageNotifier; import org.thoughtcrime.securesms.push.AccountManagerFactory; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.sms.IncomingJoinedMessage; -import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities.Capability; import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.signalservice.api.SignalServiceAccountManager; import org.whispersystems.signalservice.api.push.ContactTokenDetails; @@ -44,37 +43,8 @@ import java.util.Set; public class DirectoryHelper { - public static class UserCapabilities { - - public static final UserCapabilities UNKNOWN = new UserCapabilities(Capability.UNKNOWN, Capability.UNKNOWN, Capability.UNKNOWN); - public static final UserCapabilities UNSUPPORTED = new UserCapabilities(Capability.UNSUPPORTED, Capability.UNSUPPORTED, Capability.UNSUPPORTED); - public static final UserCapabilities SUPPORTED = new UserCapabilities(Capability.SUPPORTED, Capability.SUPPORTED, Capability.SUPPORTED); - - public enum Capability { - UNKNOWN, SUPPORTED, UNSUPPORTED - } - - private final Capability text; - private final Capability voice; - private final Capability video; - - public UserCapabilities(Capability text, Capability voice, Capability video) { - this.text = text; - this.voice = voice; - this.video = video; - } - - public Capability getTextCapability() { - return text; - } - - public Capability getVoiceCapability() { - return voice; - } - - public Capability getVideoCapability() { - return video; - } + public enum Capability { + UNKNOWN, SUPPORTED, UNSUPPORTED } private static final String TAG = DirectoryHelper.class.getSimpleName(); @@ -128,9 +98,9 @@ public class DirectoryHelper { return new RefreshResult(new LinkedList<>(), false); } - public static UserCapabilities refreshDirectoryFor(@NonNull Context context, - @Nullable MasterSecret masterSecret, - @NonNull Recipient recipient) + public static Capability refreshDirectoryFor(@NonNull Context context, + @Nullable MasterSecret masterSecret, + @NonNull Recipient recipient) throws IOException { RecipientPreferenceDatabase recipientDatabase = DatabaseFactory.getRecipientPreferenceDatabase(context); @@ -151,40 +121,36 @@ public class DirectoryHelper { notifyNewUsers(context, masterSecret, result.getNewUsers()); } - return new UserCapabilities(Capability.SUPPORTED, - details.get().isVoice() ? Capability.SUPPORTED : Capability.UNSUPPORTED, - details.get().isVideo() ? Capability.SUPPORTED : Capability.UNSUPPORTED); + return Capability.SUPPORTED; } else { recipientDatabase.setRegistered(new LinkedList<>(), Util.asList(recipient.getAddress())); - return UserCapabilities.UNSUPPORTED; + return Capability.UNSUPPORTED; } } - public static @NonNull UserCapabilities getUserCapabilities(@NonNull Context context, - @Nullable Recipient recipient) - { + public static @NonNull Capability getUserCapabilities(@NonNull Context context, @Nullable Recipient recipient) { if (recipient == null) { - return UserCapabilities.UNSUPPORTED; + return Capability.UNSUPPORTED; } if (!TextSecurePreferences.isPushRegistered(context)) { - return UserCapabilities.UNSUPPORTED; + return Capability.UNSUPPORTED; } if (recipient.isMmsGroupRecipient()) { - return UserCapabilities.UNSUPPORTED; + return Capability.UNSUPPORTED; } if (recipient.isPushGroupRecipient()) { - return new UserCapabilities(Capability.SUPPORTED, Capability.UNSUPPORTED, Capability.UNSUPPORTED); + return Capability.SUPPORTED; } final RecipientPreferenceDatabase recipientDatabase = DatabaseFactory.getRecipientPreferenceDatabase(context); final Optional recipientPreferences = recipientDatabase.getRecipientsPreferences(recipient.getAddress()); - if (recipientPreferences.isPresent() && recipientPreferences.get().isRegistered()) return UserCapabilities.SUPPORTED; - else if (recipientPreferences.isPresent()) return UserCapabilities.UNSUPPORTED; - else return UserCapabilities.UNKNOWN; + if (recipientPreferences.isPresent() && recipientPreferences.get().isRegistered()) return Capability.SUPPORTED; + else if (recipientPreferences.isPresent()) return Capability.UNSUPPORTED; + else return Capability.UNKNOWN; } private static @NonNull RefreshResult updateContactsDatabase(@NonNull Context context,