Restrict SMS in multishare.

fork-5.53.8
Alex Hart 2021-01-23 17:39:35 -04:00 zatwierdzone przez Greyson Parrelli
rodzic 68381f8b64
commit b49e4004ab
4 zmienionych plików z 91 dodań i 8 usunięć

Wyświetl plik

@ -63,6 +63,7 @@ public class ContactsCursorLoader extends CursorLoader {
public static final int FLAG_SELF = 1 << 4; public static final int FLAG_SELF = 1 << 4;
public static final int FLAG_BLOCK = 1 << 5; public static final int FLAG_BLOCK = 1 << 5;
public static final int FLAG_HIDE_GROUPS_V1 = 1 << 5; public static final int FLAG_HIDE_GROUPS_V1 = 1 << 5;
public static final int FLAG_HIDE_NEW = 1 << 6;
public static final int FLAG_ALL = FLAG_PUSH | FLAG_SMS | FLAG_ACTIVE_GROUPS | FLAG_INACTIVE_GROUPS | FLAG_SELF; public static final int FLAG_ALL = FLAG_PUSH | FLAG_SMS | FLAG_ACTIVE_GROUPS | FLAG_INACTIVE_GROUPS | FLAG_SELF;
} }
@ -135,8 +136,11 @@ public class ContactsCursorLoader extends CursorLoader {
addContactsSection(cursorList); addContactsSection(cursorList);
addGroupsSection(cursorList); addGroupsSection(cursorList);
if (!hideNewNumberOrUsername(mode)) {
addNewNumberSection(cursorList); addNewNumberSection(cursorList);
addUsernameSearchSection(cursorList); addUsernameSearchSection(cursorList);
}
return cursorList; return cursorList;
} }
@ -429,6 +433,10 @@ public class ContactsCursorLoader extends CursorLoader {
return flagSet(mode, DisplayMode.FLAG_HIDE_GROUPS_V1); return flagSet(mode, DisplayMode.FLAG_HIDE_GROUPS_V1);
} }
private static boolean hideNewNumberOrUsername(int mode) {
return flagSet(mode, DisplayMode.FLAG_HIDE_NEW);
}
private static boolean flagSet(int mode, int flag) { private static boolean flagSet(int mode, int flag) {
return (mode & flag) > 0; return (mode & flag) > 0;
} }

Wyświetl plik

@ -98,6 +98,7 @@ public class ShareActivity extends PassphraseRequiredActivity
private ImageView searchAction; private ImageView searchAction;
private View shareConfirm; private View shareConfirm;
private ShareSelectionAdapter adapter; private ShareSelectionAdapter adapter;
private boolean disallowMultiShare;
private ShareViewModel viewModel; private ShareViewModel viewModel;
@ -173,8 +174,13 @@ public class ShareActivity extends PassphraseRequiredActivity
@Override @Override
public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) { public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
if (disallowMultiShare) {
Toast.makeText(this, R.string.ShareActivity__sharing_to_multiple_chats_is, Toast.LENGTH_LONG).show();
return false;
} else {
return viewModel.onContactSelected(new ShareContact(recipientId, number)); return viewModel.onContactSelected(new ShareContact(recipientId, number));
} }
}
@Override @Override
public void onContactDeselected(@NonNull Optional<RecipientId> recipientId, String number) { public void onContactDeselected(@NonNull Optional<RecipientId> recipientId, String number) {
@ -203,7 +209,7 @@ public class ShareActivity extends PassphraseRequiredActivity
private void initializeIntent() { private void initializeIntent() {
if (!getIntent().hasExtra(ContactSelectionListFragment.DISPLAY_MODE)) { if (!getIntent().hasExtra(ContactSelectionListFragment.DISPLAY_MODE)) {
int mode = DisplayMode.FLAG_PUSH | DisplayMode.FLAG_ACTIVE_GROUPS | DisplayMode.FLAG_SELF; int mode = DisplayMode.FLAG_PUSH | DisplayMode.FLAG_ACTIVE_GROUPS | DisplayMode.FLAG_SELF | DisplayMode.FLAG_HIDE_NEW;
if (TextSecurePreferences.isSmsEnabled(this) && viewModel.isExternalShare()) { if (TextSecurePreferences.isSmsEnabled(this) && viewModel.isExternalShare()) {
mode |= DisplayMode.FLAG_SMS; mode |= DisplayMode.FLAG_SMS;
@ -269,6 +275,42 @@ public class ShareActivity extends PassphraseRequiredActivity
animateInSelection(); animateInSelection();
} }
}); });
viewModel.getSmsShareRestriction().observe(this, smsShareRestriction -> {
final int displayMode;
switch (smsShareRestriction) {
case NO_RESTRICTIONS:
disallowMultiShare = false;
displayMode = getIntent().getIntExtra(ContactSelectionListFragment.DISPLAY_MODE, -1);
if (displayMode == -1) {
Log.w(TAG, "DisplayMode not set yet.");
return;
}
if (TextSecurePreferences.isSmsEnabled(this) && viewModel.isExternalShare() && (displayMode & DisplayMode.FLAG_SMS) == 0) {
getIntent().putExtra(ContactSelectionListFragment.DISPLAY_MODE, displayMode | DisplayMode.FLAG_SMS);
contactsFragment.setQueryFilter(null);
}
break;
case DISALLOW_SMS_CONTACTS:
disallowMultiShare = false;
displayMode = getIntent().getIntExtra(ContactSelectionListFragment.DISPLAY_MODE, -1);
if (displayMode == -1) {
Log.w(TAG, "DisplayMode not set yet.");
return;
}
getIntent().putExtra(ContactSelectionListFragment.DISPLAY_MODE, displayMode & ~DisplayMode.FLAG_SMS);
contactsFragment.setQueryFilter(null);
break;
case DISALLOW_MULTI_SHARE:
disallowMultiShare = true;
break;
}
});
} }
private void initializeViewModel() { private void initializeViewModel() {

Wyświetl plik

@ -5,6 +5,7 @@ import android.net.Uri;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations; import androidx.lifecycle.Transformations;
@ -16,8 +17,10 @@ import com.annimon.stream.Stream;
import org.signal.core.util.logging.Log; import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies; import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.providers.BlobProvider; import org.thoughtcrime.securesms.providers.BlobProvider;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.DefaultValueLiveData; import org.thoughtcrime.securesms.util.DefaultValueLiveData;
import org.thoughtcrime.securesms.util.MappingModel; import org.thoughtcrime.securesms.util.MappingModel;
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Collections; import java.util.Collections;
@ -33,6 +36,7 @@ public class ShareViewModel extends ViewModel {
private final ShareRepository shareRepository; private final ShareRepository shareRepository;
private final MutableLiveData<Optional<ShareData>> shareData; private final MutableLiveData<Optional<ShareData>> shareData;
private final MutableLiveData<Set<ShareContact>> selectedContacts; private final MutableLiveData<Set<ShareContact>> selectedContacts;
private final LiveData<SmsShareRestriction> smsShareRestriction;
private boolean mediaUsed; private boolean mediaUsed;
private boolean externalShare; private boolean externalShare;
@ -42,6 +46,7 @@ public class ShareViewModel extends ViewModel {
this.shareRepository = new ShareRepository(); this.shareRepository = new ShareRepository();
this.shareData = new MutableLiveData<>(); this.shareData = new MutableLiveData<>();
this.selectedContacts = new DefaultValueLiveData<>(Collections.emptySet()); this.selectedContacts = new DefaultValueLiveData<>(Collections.emptySet());
this.smsShareRestriction = Transformations.map(selectedContacts, this::updateShareRestriction);
} }
void onSingleMediaShared(@NonNull Uri uri, @Nullable String mimeType) { void onSingleMediaShared(@NonNull Uri uri, @Nullable String mimeType) {
@ -90,6 +95,10 @@ public class ShareViewModel extends ViewModel {
.toList()); .toList());
} }
@NonNull LiveData<SmsShareRestriction> getSmsShareRestriction() {
return Transformations.distinctUntilChanged(smsShareRestriction);
}
void onNonExternalShare() { void onNonExternalShare() {
externalShare = false; externalShare = false;
} }
@ -116,6 +125,23 @@ public class ShareViewModel extends ViewModel {
} }
} }
private @NonNull SmsShareRestriction updateShareRestriction(@NonNull Set<ShareContact> shareContacts) {
if (shareContacts.isEmpty()) {
return SmsShareRestriction.NO_RESTRICTIONS;
} else if (shareContacts.size() == 1) {
ShareContact shareContact = shareContacts.iterator().next();
Recipient recipient = Recipient.live(shareContact.getRecipientId().get()).get();
if (!recipient.isRegistered() || recipient.isForceSmsSelection()) {
return SmsShareRestriction.DISALLOW_MULTI_SHARE;
} else {
return SmsShareRestriction.DISALLOW_SMS_CONTACTS;
}
} else {
return SmsShareRestriction.DISALLOW_SMS_CONTACTS;
}
}
public static class Factory extends ViewModelProvider.NewInstanceFactory { public static class Factory extends ViewModelProvider.NewInstanceFactory {
@Override @Override
public @NonNull<T extends ViewModel> T create(@NonNull Class<T> modelClass) { public @NonNull<T extends ViewModel> T create(@NonNull Class<T> modelClass) {
@ -123,4 +149,10 @@ public class ShareViewModel extends ViewModel {
return modelClass.cast(new ShareViewModel()); return modelClass.cast(new ShareViewModel());
} }
} }
enum SmsShareRestriction {
NO_RESTRICTIONS,
DISALLOW_SMS_CONTACTS,
DISALLOW_MULTI_SHARE
}
} }

Wyświetl plik

@ -2827,6 +2827,7 @@
<string name="ShareActivity__share">Share</string> <string name="ShareActivity__share">Share</string>
<string name="ShareActivity__send">Send</string> <string name="ShareActivity__send">Send</string>
<string name="ShareActivity__s_comma">%1$s,</string> <string name="ShareActivity__s_comma">%1$s,</string>
<string name="ShareActivity__sharing_to_multiple_chats_is">Sharing to multiple chats is only supported for Signal messages</string>
<!-- MultiShareDialogs --> <!-- MultiShareDialogs -->
<string name="MultiShareDialogs__failed_to_send_to_some_users">Failed to send to some users</string> <string name="MultiShareDialogs__failed_to_send_to_some_users">Failed to send to some users</string>