Collapse KnownRecipient / Story into single model.

This commit is contained in:
Alex Hart
2023-01-18 10:49:47 -04:00
committed by Cody Henthorne
parent 70c6e9e60f
commit 8e313f8387
25 changed files with 93 additions and 137 deletions

View File

@@ -24,6 +24,7 @@ import org.thoughtcrime.securesms.util.Util;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -61,11 +62,9 @@ public final class MultiShareArgs implements Parcelable {
}
protected MultiShareArgs(Parcel in) {
List<ContactSearchKey.ParcelableRecipientSearchKey> parcelableRecipientSearchKeys = in.createTypedArrayList(ContactSearchKey.ParcelableRecipientSearchKey.CREATOR);
List<ContactSearchKey.RecipientSearchKey> parcelableRecipientSearchKeys = in.createTypedArrayList(ContactSearchKey.RecipientSearchKey.CREATOR);
contactSearchKeys = parcelableRecipientSearchKeys.stream()
.map(ContactSearchKey.ParcelableRecipientSearchKey::asRecipientSearchKey)
.collect(Collectors.toSet());
contactSearchKeys = new HashSet<>(parcelableRecipientSearchKeys);
media = in.createTypedArrayList(Media.CREATOR);
draftText = in.readString();
stickerLocator = in.readParcelable(StickerLocator.class.getClassLoader());
@@ -197,7 +196,8 @@ public final class MultiShareArgs implements Parcelable {
}
public boolean allRecipientsAreStories() {
return !contactSearchKeys.isEmpty() && contactSearchKeys.stream().allMatch(key -> key instanceof ContactSearchKey.RecipientSearchKey.Story);
return !contactSearchKeys.isEmpty() && contactSearchKeys.stream()
.allMatch(key -> key.requireRecipientSearchKey().isStory());
}
public static final Creator<MultiShareArgs> CREATOR = new Creator<MultiShareArgs>() {
@@ -219,7 +219,7 @@ public final class MultiShareArgs implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeTypedList(Stream.of(contactSearchKeys).map(ContactSearchKey::requireParcelable).toList());
dest.writeTypedList(Stream.of(contactSearchKeys).map(ContactSearchKey::requireRecipientSearchKey).toList());
dest.writeTypedList(media);
dest.writeString(draftText);
dest.writeParcelable(stickerLocator, flags);
@@ -267,7 +267,7 @@ public final class MultiShareArgs implements Parcelable {
(!media.isEmpty() ||
!TextUtils.isEmpty(draftText) ||
MediaUtil.isImageOrVideoType(dataType) ||
(!contactSearchKeys.isEmpty() && contactSearchKeys.stream().anyMatch(key -> key instanceof ContactSearchKey.RecipientSearchKey.Story)));
(!contactSearchKeys.isEmpty() && contactSearchKeys.stream().anyMatch(key -> key.requireRecipientSearchKey().isStory())));
}
public static final class Builder {

View File

@@ -103,7 +103,7 @@ class ShareActivity : PassphraseRequiredActivity(), MultiselectForwardFragment.C
openConversation(
ShareEvent.OpenConversation(
shareState.loadState.resolvedShareData,
ContactSearchKey.RecipientSearchKey.KnownRecipient(directShareTarget)
ContactSearchKey.RecipientSearchKey(directShareTarget, false)
)
)
} else {
@@ -134,8 +134,7 @@ class ShareActivity : PassphraseRequiredActivity(), MultiselectForwardFragment.C
throw AssertionError("Expected a recipient selection!")
}
val parcelizedKeys: List<ContactSearchKey.ParcelableRecipientSearchKey> = bundle.getParcelableArrayList(MultiselectForwardFragment.RESULT_SELECTION)!!
val contactSearchKeys = parcelizedKeys.map { it.asRecipientSearchKey() }
val contactSearchKeys: List<ContactSearchKey.RecipientSearchKey> = bundle.getParcelableArrayList(MultiselectForwardFragment.RESULT_SELECTION)!!
viewModel.onContactSelectionConfirmed(contactSearchKeys)
}