mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Consolidate user "capability" enums to a single value
// FREEBIE
This commit is contained in:
parent
5a5e47f2df
commit
f61c52aace
@ -143,8 +143,7 @@ import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
|||||||
import org.thoughtcrime.securesms.util.CharacterCalculator.CharacterState;
|
import org.thoughtcrime.securesms.util.CharacterCalculator.CharacterState;
|
||||||
import org.thoughtcrime.securesms.util.Dialogs;
|
import org.thoughtcrime.securesms.util.Dialogs;
|
||||||
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
||||||
import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities;
|
import org.thoughtcrime.securesms.util.DirectoryHelper.Capability;
|
||||||
import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities.Capability;
|
|
||||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||||
import org.thoughtcrime.securesms.util.ExpirationUtil;
|
import org.thoughtcrime.securesms.util.ExpirationUtil;
|
||||||
@ -1016,19 +1015,17 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
protected boolean[] doInBackground(Recipient... params) {
|
protected boolean[] doInBackground(Recipient... params) {
|
||||||
Context context = ConversationActivity.this;
|
Context context = ConversationActivity.this;
|
||||||
Recipient recipient = params[0];
|
Recipient recipient = params[0];
|
||||||
UserCapabilities capabilities = DirectoryHelper.getUserCapabilities(context, recipient);
|
Capability capability = DirectoryHelper.getUserCapabilities(context, recipient);
|
||||||
|
|
||||||
if (capabilities.getTextCapability() == Capability.UNKNOWN ||
|
if (capability == Capability.UNKNOWN) {
|
||||||
capabilities.getVideoCapability() == Capability.UNKNOWN)
|
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
capabilities = DirectoryHelper.refreshDirectoryFor(context, masterSecret, recipient);
|
capability = DirectoryHelper.refreshDirectoryFor(context, masterSecret, recipient);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w(TAG, 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
|
@Override
|
||||||
|
@ -407,9 +407,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
|||||||
DatabaseFactory.getRecipientPreferenceDatabase(context)
|
DatabaseFactory.getRecipientPreferenceDatabase(context)
|
||||||
.setColor(recipient, selectedColor);
|
.setColor(recipient, selectedColor);
|
||||||
|
|
||||||
if (DirectoryHelper.getUserCapabilities(context, recipient)
|
if (DirectoryHelper.getUserCapabilities(context, recipient) == DirectoryHelper.Capability.SUPPORTED) {
|
||||||
.getTextCapability() == DirectoryHelper.UserCapabilities.Capability.SUPPORTED)
|
|
||||||
{
|
|
||||||
ApplicationContext.getInstance(context)
|
ApplicationContext.getInstance(context)
|
||||||
.getJobManager()
|
.getJobManager()
|
||||||
.add(new MultiDeviceContactUpdateJob(context, recipient.getAddress()));
|
.add(new MultiDeviceContactUpdateJob(context, recipient.getAddress()));
|
||||||
|
@ -32,7 +32,6 @@ import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||||
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
||||||
import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities.Capability;
|
|
||||||
import org.thoughtcrime.securesms.util.NumberUtil;
|
import org.thoughtcrime.securesms.util.NumberUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -106,7 +105,7 @@ public class ContactsCursorLoader extends CursorLoader {
|
|||||||
final String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_COLUMN));
|
final String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_COLUMN));
|
||||||
final Recipient recipient = RecipientFactory.getRecipientFor(getContext(), Address.fromExternal(getContext(), number), true);
|
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)),
|
matrix.addRow(new Object[]{cursor.getLong(cursor.getColumnIndexOrThrow(ContactsDatabase.ID_COLUMN)),
|
||||||
cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NAME_COLUMN)),
|
cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NAME_COLUMN)),
|
||||||
number,
|
number,
|
||||||
|
@ -30,7 +30,6 @@ import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
|||||||
import org.thoughtcrime.securesms.push.AccountManagerFactory;
|
import org.thoughtcrime.securesms.push.AccountManagerFactory;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.sms.IncomingJoinedMessage;
|
import org.thoughtcrime.securesms.sms.IncomingJoinedMessage;
|
||||||
import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities.Capability;
|
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
||||||
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
|
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
|
||||||
@ -44,39 +43,10 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class DirectoryHelper {
|
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 {
|
public enum Capability {
|
||||||
UNKNOWN, SUPPORTED, UNSUPPORTED
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String TAG = DirectoryHelper.class.getSimpleName();
|
private static final String TAG = DirectoryHelper.class.getSimpleName();
|
||||||
|
|
||||||
public static void refreshDirectory(@NonNull Context context, @Nullable MasterSecret masterSecret)
|
public static void refreshDirectory(@NonNull Context context, @Nullable MasterSecret masterSecret)
|
||||||
@ -128,7 +98,7 @@ public class DirectoryHelper {
|
|||||||
return new RefreshResult(new LinkedList<>(), false);
|
return new RefreshResult(new LinkedList<>(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserCapabilities refreshDirectoryFor(@NonNull Context context,
|
public static Capability refreshDirectoryFor(@NonNull Context context,
|
||||||
@Nullable MasterSecret masterSecret,
|
@Nullable MasterSecret masterSecret,
|
||||||
@NonNull Recipient recipient)
|
@NonNull Recipient recipient)
|
||||||
throws IOException
|
throws IOException
|
||||||
@ -151,40 +121,36 @@ public class DirectoryHelper {
|
|||||||
notifyNewUsers(context, masterSecret, result.getNewUsers());
|
notifyNewUsers(context, masterSecret, result.getNewUsers());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new UserCapabilities(Capability.SUPPORTED,
|
return Capability.SUPPORTED;
|
||||||
details.get().isVoice() ? Capability.SUPPORTED : Capability.UNSUPPORTED,
|
|
||||||
details.get().isVideo() ? Capability.SUPPORTED : Capability.UNSUPPORTED);
|
|
||||||
} else {
|
} else {
|
||||||
recipientDatabase.setRegistered(new LinkedList<>(), Util.asList(recipient.getAddress()));
|
recipientDatabase.setRegistered(new LinkedList<>(), Util.asList(recipient.getAddress()));
|
||||||
return UserCapabilities.UNSUPPORTED;
|
return Capability.UNSUPPORTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NonNull UserCapabilities getUserCapabilities(@NonNull Context context,
|
public static @NonNull Capability getUserCapabilities(@NonNull Context context, @Nullable Recipient recipient) {
|
||||||
@Nullable Recipient recipient)
|
|
||||||
{
|
|
||||||
if (recipient == null) {
|
if (recipient == null) {
|
||||||
return UserCapabilities.UNSUPPORTED;
|
return Capability.UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TextSecurePreferences.isPushRegistered(context)) {
|
if (!TextSecurePreferences.isPushRegistered(context)) {
|
||||||
return UserCapabilities.UNSUPPORTED;
|
return Capability.UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recipient.isMmsGroupRecipient()) {
|
if (recipient.isMmsGroupRecipient()) {
|
||||||
return UserCapabilities.UNSUPPORTED;
|
return Capability.UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recipient.isPushGroupRecipient()) {
|
if (recipient.isPushGroupRecipient()) {
|
||||||
return new UserCapabilities(Capability.SUPPORTED, Capability.UNSUPPORTED, Capability.UNSUPPORTED);
|
return Capability.SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
final RecipientPreferenceDatabase recipientDatabase = DatabaseFactory.getRecipientPreferenceDatabase(context);
|
final RecipientPreferenceDatabase recipientDatabase = DatabaseFactory.getRecipientPreferenceDatabase(context);
|
||||||
final Optional<RecipientsPreferences> recipientPreferences = recipientDatabase.getRecipientsPreferences(recipient.getAddress());
|
final Optional<RecipientsPreferences> recipientPreferences = recipientDatabase.getRecipientsPreferences(recipient.getAddress());
|
||||||
|
|
||||||
if (recipientPreferences.isPresent() && recipientPreferences.get().isRegistered()) return UserCapabilities.SUPPORTED;
|
if (recipientPreferences.isPresent() && recipientPreferences.get().isRegistered()) return Capability.SUPPORTED;
|
||||||
else if (recipientPreferences.isPresent()) return UserCapabilities.UNSUPPORTED;
|
else if (recipientPreferences.isPresent()) return Capability.UNSUPPORTED;
|
||||||
else return UserCapabilities.UNKNOWN;
|
else return Capability.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @NonNull RefreshResult updateContactsDatabase(@NonNull Context context,
|
private static @NonNull RefreshResult updateContactsDatabase(@NonNull Context context,
|
||||||
|
Loading…
Reference in New Issue
Block a user