2022-02-24 17:40:28 +00:00
|
|
|
package org.thoughtcrime.securesms.contacts.paged
|
|
|
|
|
2022-09-22 16:21:53 +00:00
|
|
|
import androidx.annotation.CheckResult
|
2022-06-29 12:57:06 +00:00
|
|
|
import io.reactivex.rxjava3.core.Completable
|
2022-02-24 17:40:28 +00:00
|
|
|
import io.reactivex.rxjava3.core.Single
|
2022-06-29 12:57:06 +00:00
|
|
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
2022-11-29 15:47:12 +00:00
|
|
|
import org.thoughtcrime.securesms.database.GroupTable
|
2022-02-24 17:40:28 +00:00
|
|
|
import org.thoughtcrime.securesms.database.SignalDatabase
|
2022-06-29 12:57:06 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.DistributionListId
|
|
|
|
import org.thoughtcrime.securesms.groups.GroupId
|
2022-02-24 17:40:28 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient
|
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientId
|
2022-09-22 16:21:53 +00:00
|
|
|
import org.thoughtcrime.securesms.storage.StorageSyncHelper
|
2022-06-29 12:57:06 +00:00
|
|
|
import org.thoughtcrime.securesms.stories.Stories
|
2022-02-24 17:40:28 +00:00
|
|
|
|
|
|
|
class ContactSearchRepository {
|
2022-09-22 16:21:53 +00:00
|
|
|
@CheckResult
|
2022-02-24 17:40:28 +00:00
|
|
|
fun filterOutUnselectableContactSearchKeys(contactSearchKeys: Set<ContactSearchKey>): Single<Set<ContactSearchSelectionResult>> {
|
|
|
|
return Single.fromCallable {
|
|
|
|
contactSearchKeys.map {
|
|
|
|
val isSelectable = when (it) {
|
|
|
|
is ContactSearchKey.Expand -> false
|
|
|
|
is ContactSearchKey.Header -> false
|
2023-01-18 14:49:47 +00:00
|
|
|
is ContactSearchKey.RecipientSearchKey -> canSelectRecipient(it.recipientId)
|
2022-02-24 17:40:28 +00:00
|
|
|
}
|
|
|
|
ContactSearchSelectionResult(it, isSelectable)
|
|
|
|
}.toSet()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun canSelectRecipient(recipientId: RecipientId): Boolean {
|
|
|
|
val recipient = Recipient.resolved(recipientId)
|
|
|
|
return if (recipient.isPushV2Group) {
|
|
|
|
val record = SignalDatabase.groups.getGroup(recipient.requireGroupId())
|
|
|
|
!(record.isPresent && record.get().isAnnouncementGroup && !record.get().isAdmin(Recipient.self()))
|
|
|
|
} else {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
2022-06-29 12:57:06 +00:00
|
|
|
|
2022-09-22 16:21:53 +00:00
|
|
|
@CheckResult
|
|
|
|
fun markDisplayAsStory(recipientIds: Collection<RecipientId>): Completable {
|
|
|
|
return Completable.fromAction {
|
2022-11-29 15:47:12 +00:00
|
|
|
SignalDatabase.groups.setShowAsStoryState(recipientIds, GroupTable.ShowAsStoryState.ALWAYS)
|
2022-09-22 16:21:53 +00:00
|
|
|
SignalDatabase.recipients.markNeedsSync(recipientIds)
|
|
|
|
StorageSyncHelper.scheduleSyncForDataChange()
|
|
|
|
}.subscribeOn(Schedulers.io())
|
|
|
|
}
|
|
|
|
|
|
|
|
@CheckResult
|
2022-06-29 12:57:06 +00:00
|
|
|
fun unmarkDisplayAsStory(groupId: GroupId): Completable {
|
|
|
|
return Completable.fromAction {
|
2022-11-29 15:47:12 +00:00
|
|
|
SignalDatabase.groups.setShowAsStoryState(groupId, GroupTable.ShowAsStoryState.NEVER)
|
2022-09-22 16:21:53 +00:00
|
|
|
SignalDatabase.recipients.markNeedsSync(Recipient.externalGroupExact(groupId).id)
|
|
|
|
StorageSyncHelper.scheduleSyncForDataChange()
|
2022-06-29 12:57:06 +00:00
|
|
|
}.subscribeOn(Schedulers.io())
|
|
|
|
}
|
|
|
|
|
2022-09-22 16:21:53 +00:00
|
|
|
@CheckResult
|
2022-06-29 12:57:06 +00:00
|
|
|
fun deletePrivateStory(distributionListId: DistributionListId): Completable {
|
|
|
|
return Completable.fromAction {
|
|
|
|
SignalDatabase.distributionLists.deleteList(distributionListId)
|
|
|
|
Stories.onStorySettingsChanged(distributionListId)
|
|
|
|
}.subscribeOn(Schedulers.io())
|
|
|
|
}
|
2022-02-24 17:40:28 +00:00
|
|
|
}
|