Disable interactions while user is unregistered or expired.

This commit is contained in:
Clark
2023-05-05 13:24:00 -04:00
committed by Cody Henthorne
parent 65d5f4c426
commit c2c1537858
37 changed files with 527 additions and 44 deletions

View File

@@ -49,6 +49,8 @@ import org.thoughtcrime.securesms.util.ThemeUtil;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.WindowUtil;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import kotlin.Unit;
@@ -87,6 +89,8 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
private BadgeImageView badgeImageView;
private Callback callback;
private ButtonStripPreference.ViewHolder buttonStripViewHolder;
public static BottomSheetDialogFragment create(@NonNull RecipientId recipientId,
@Nullable GroupId groupId)
{
@@ -135,6 +139,7 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
interactionsContainer = view.findViewById(R.id.interactions_container);
badgeImageView = view.findViewById(R.id.rbs_badge);
buttonStripViewHolder = new ButtonStripPreference.ViewHolder(buttonStrip);
return view;
}
@@ -245,6 +250,7 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
ButtonStripPreference.Model buttonStripModel = new ButtonStripPreference.Model(
buttonStripState,
DSLSettingsIcon.from(ContextUtil.requireDrawable(requireContext(), R.drawable.selectable_recipient_bottom_sheet_icon_button)),
!viewModel.isDeprecatedOrUnregistered(),
() -> Unit.INSTANCE,
() -> {
dismiss();
@@ -267,7 +273,7 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
() -> Unit.INSTANCE
);
new ButtonStripPreference.ViewHolder(buttonStrip).bind(buttonStripModel);
buttonStripViewHolder.bind(buttonStripModel);
if (recipient.isReleaseNotes()) {
buttonStrip.setVisibility(View.GONE);
@@ -342,12 +348,21 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
viewModel.getAdminActionBusy().observe(getViewLifecycleOwner(), busy -> {
adminActionBusy.setVisibility(busy ? View.VISIBLE : View.GONE);
makeGroupAdminButton.setEnabled(!busy);
removeAdminButton.setEnabled(!busy);
removeFromGroupButton.setEnabled(!busy);
boolean userLoggedOut = viewModel.isDeprecatedOrUnregistered();
makeGroupAdminButton.setEnabled(!busy && !userLoggedOut);
removeAdminButton.setEnabled(!busy && !userLoggedOut);
removeFromGroupButton.setEnabled(!busy && !userLoggedOut);
});
callback = getParentFragment() != null && getParentFragment() instanceof Callback ? (Callback) getParentFragment() : null;
if (viewModel.isDeprecatedOrUnregistered()) {
List<TextView> viewsToDisable = Arrays.asList(blockButton, unblockButton, removeFromGroupButton, makeGroupAdminButton, removeAdminButton, addToGroupButton, viewSafetyNumberButton);
for (TextView view : viewsToDisable) {
view.setEnabled(false);
view.setAlpha(0.5f);
}
}
}
@Override

View File

@@ -29,12 +29,14 @@ import org.thoughtcrime.securesms.groups.LiveGroup;
import org.thoughtcrime.securesms.groups.ui.GroupChangeFailureReason;
import org.thoughtcrime.securesms.groups.ui.GroupErrors;
import org.thoughtcrime.securesms.groups.ui.addtogroup.AddToGroupsActivity;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.recipients.RecipientUtil;
import org.thoughtcrime.securesms.stories.StoryViewerArgs;
import org.thoughtcrime.securesms.stories.viewer.StoryViewerActivity;
import org.thoughtcrime.securesms.util.CommunicationActions;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
import org.thoughtcrime.securesms.verify.VerifyIdentityActivity;
@@ -54,16 +56,17 @@ final class RecipientDialogViewModel extends ViewModel {
private final MutableLiveData<Boolean> adminActionBusy;
private final MutableLiveData<StoryViewState> storyViewState;
private final CompositeDisposable disposables;
private final boolean isDeprecatedOrUnregistered;
private RecipientDialogViewModel(@NonNull Context context,
@NonNull RecipientDialogRepository recipientDialogRepository)
{
this.context = context;
this.recipientDialogRepository = recipientDialogRepository;
this.identity = new MutableLiveData<>();
this.adminActionBusy = new MutableLiveData<>(false);
this.storyViewState = new MutableLiveData<>();
this.disposables = new CompositeDisposable();
this.context = context;
this.recipientDialogRepository = recipientDialogRepository;
this.identity = new MutableLiveData<>();
this.adminActionBusy = new MutableLiveData<>(false);
this.storyViewState = new MutableLiveData<>();
this.disposables = new CompositeDisposable();
this.isDeprecatedOrUnregistered = SignalStore.misc().isClientDeprecated() || TextSecurePreferences.isUnauthorizedReceived(context);
boolean recipientIsSelf = recipientDialogRepository.getRecipientId().equals(Recipient.self().getId());
@@ -113,6 +116,10 @@ final class RecipientDialogViewModel extends ViewModel {
disposables.clear();
}
boolean isDeprecatedOrUnregistered() {
return isDeprecatedOrUnregistered;
}
LiveData<StoryViewState> getStoryViewState() {
return storyViewState;
}