mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
Collapse KnownRecipient / Story into single model.
This commit is contained in:
committed by
Cody Henthorne
parent
70c6e9e60f
commit
8e313f8387
@@ -18,7 +18,7 @@ sealed class ContactSearchData(val contactSearchKey: ContactSearchKey) {
|
||||
val recipient: Recipient,
|
||||
val count: Int,
|
||||
val privacyMode: DistributionListPrivacyMode
|
||||
) : ContactSearchData(ContactSearchKey.RecipientSearchKey.Story(recipient.id))
|
||||
) : ContactSearchData(ContactSearchKey.RecipientSearchKey(recipient.id, true))
|
||||
|
||||
/**
|
||||
* A row displaying a known recipient.
|
||||
@@ -27,7 +27,7 @@ sealed class ContactSearchData(val contactSearchKey: ContactSearchKey) {
|
||||
val recipient: Recipient,
|
||||
val shortSummary: Boolean = false,
|
||||
val headerLetter: String? = null
|
||||
) : ContactSearchData(ContactSearchKey.RecipientSearchKey.KnownRecipient(recipient.id))
|
||||
) : ContactSearchData(ContactSearchKey.RecipientSearchKey(recipient.id, false))
|
||||
|
||||
/**
|
||||
* A row containing a title for a given section
|
||||
|
||||
@@ -12,44 +12,18 @@ sealed class ContactSearchKey {
|
||||
|
||||
/**
|
||||
* Generates a ShareContact object used to display which contacts have been selected. This should *not*
|
||||
* be used for the final sharing process, as it is not always truthful about, for example, KnownRecipient of
|
||||
* be used for the final sharing process, as it is not always truthful about, for example,
|
||||
* a group vs. a group's Story.
|
||||
*/
|
||||
open fun requireShareContact(): ShareContact = error("This key cannot be converted into a ShareContact")
|
||||
|
||||
open fun requireParcelable(): ParcelableRecipientSearchKey = error("This key cannot be parcelized")
|
||||
open fun requireRecipientSearchKey(): RecipientSearchKey = error("This key cannot be parcelized")
|
||||
|
||||
sealed class RecipientSearchKey : ContactSearchKey() {
|
||||
@Parcelize
|
||||
data class RecipientSearchKey(val recipientId: RecipientId, val isStory: Boolean) : ContactSearchKey(), Parcelable {
|
||||
override fun requireRecipientSearchKey(): RecipientSearchKey = this
|
||||
|
||||
abstract val recipientId: RecipientId
|
||||
abstract val isStory: Boolean
|
||||
|
||||
data class Story(override val recipientId: RecipientId) : RecipientSearchKey() {
|
||||
override fun requireShareContact(): ShareContact {
|
||||
return ShareContact(recipientId)
|
||||
}
|
||||
|
||||
override fun requireParcelable(): ParcelableRecipientSearchKey {
|
||||
return ParcelableRecipientSearchKey(ParcelableType.STORY, recipientId)
|
||||
}
|
||||
|
||||
override val isStory: Boolean = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Key to a recipient which already exists in our database
|
||||
*/
|
||||
data class KnownRecipient(override val recipientId: RecipientId) : RecipientSearchKey() {
|
||||
override fun requireShareContact(): ShareContact {
|
||||
return ShareContact(recipientId)
|
||||
}
|
||||
|
||||
override fun requireParcelable(): ParcelableRecipientSearchKey {
|
||||
return ParcelableRecipientSearchKey(ParcelableType.KNOWN_RECIPIENT, recipientId)
|
||||
}
|
||||
|
||||
override val isStory: Boolean = false
|
||||
}
|
||||
override fun requireShareContact(): ShareContact = ShareContact(recipientId)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,19 +35,4 @@ sealed class ContactSearchKey {
|
||||
* Key to an expand button for a given section
|
||||
*/
|
||||
data class Expand(val sectionKey: ContactSearchConfiguration.SectionKey) : ContactSearchKey()
|
||||
|
||||
@Parcelize
|
||||
data class ParcelableRecipientSearchKey(val type: ParcelableType, val recipientId: RecipientId) : Parcelable {
|
||||
fun asRecipientSearchKey(): RecipientSearchKey {
|
||||
return when (type) {
|
||||
ParcelableType.STORY -> RecipientSearchKey.Story(recipientId)
|
||||
ParcelableType.KNOWN_RECIPIENT -> RecipientSearchKey.KnownRecipient(recipientId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class ParcelableType {
|
||||
STORY,
|
||||
KNOWN_RECIPIENT
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class ContactSearchMediator(
|
||||
return viewModel.errorEventsStream.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
fun addToVisibleGroupStories(groupStories: Set<ContactSearchKey.RecipientSearchKey.Story>) {
|
||||
fun addToVisibleGroupStories(groupStories: Set<ContactSearchKey.RecipientSearchKey>) {
|
||||
viewModel.addToVisibleGroupStories(groupStories)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,7 @@ class ContactSearchRepository {
|
||||
val isSelectable = when (it) {
|
||||
is ContactSearchKey.Expand -> false
|
||||
is ContactSearchKey.Header -> false
|
||||
is ContactSearchKey.RecipientSearchKey.KnownRecipient -> canSelectRecipient(it.recipientId)
|
||||
is ContactSearchKey.RecipientSearchKey.Story -> canSelectRecipient(it.recipientId)
|
||||
is ContactSearchKey.RecipientSearchKey -> canSelectRecipient(it.recipientId)
|
||||
}
|
||||
ContactSearchSelectionResult(it, isSelectable)
|
||||
}.toSet()
|
||||
|
||||
@@ -98,7 +98,7 @@ class ContactSearchViewModel(
|
||||
return selectionStore.state
|
||||
}
|
||||
|
||||
fun addToVisibleGroupStories(groupStories: Set<ContactSearchKey.RecipientSearchKey.Story>) {
|
||||
fun addToVisibleGroupStories(groupStories: Set<ContactSearchKey.RecipientSearchKey>) {
|
||||
disposables += contactSearchRepository.markDisplayAsStory(groupStories.map { it.recipientId }).subscribe {
|
||||
configurationStore.update { state ->
|
||||
state.copy(
|
||||
|
||||
@@ -77,8 +77,8 @@ class SafetyNumberRepository(
|
||||
private fun List<ContactSearchKey>.flattenToRecipientIds(): Set<RecipientId> {
|
||||
return this
|
||||
.map {
|
||||
when (it) {
|
||||
is ContactSearchKey.RecipientSearchKey.KnownRecipient -> {
|
||||
when {
|
||||
it is ContactSearchKey.RecipientSearchKey && !it.isStory -> {
|
||||
val recipient = Recipient.resolved(it.recipientId)
|
||||
if (recipient.isGroup) {
|
||||
recipient.participantIds
|
||||
@@ -86,7 +86,7 @@ class SafetyNumberRepository(
|
||||
listOf(it.recipientId)
|
||||
}
|
||||
}
|
||||
is ContactSearchKey.RecipientSearchKey.Story -> Recipient.resolved(it.recipientId).participantIds
|
||||
it is ContactSearchKey.RecipientSearchKey -> Recipient.resolved(it.recipientId).participantIds
|
||||
else -> throw AssertionError("Invalid contact selection $it")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user