CFV2 -- Add to Contacts / Mute Conversation.

This commit is contained in:
Alex Hart
2023-05-30 13:15:50 -03:00
committed by Cody Henthorne
parent 045d2cf42f
commit be01f2b511
5 changed files with 58 additions and 4 deletions

View File

@@ -18,6 +18,8 @@ import org.thoughtcrime.securesms.contactshare.Contact
import org.thoughtcrime.securesms.contactshare.ContactUtil import org.thoughtcrime.securesms.contactshare.ContactUtil
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.jobs.DirectoryRefreshJob import org.thoughtcrime.securesms.jobs.DirectoryRefreshJob
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.recipients.RecipientExporter
/** /**
* Wraps up the "Add shared contact to contact list" into a contract. The flow here is a little * Wraps up the "Add shared contact to contact list" into a contract. The flow here is a little
@@ -44,7 +46,31 @@ class AddToContactsContract : ActivityResultContract<Intent, Unit>() {
launcher: ActivityResultLauncher<Intent>, launcher: ActivityResultLauncher<Intent>,
contact: Contact contact: Contact
): Disposable { ): Disposable {
return Single.fromCallable { ContactUtil.buildAddToContactsIntent(fragment.requireContext(), contact) } return launchIntent(
fragment = fragment,
launcher = launcher,
intentProducer = Single.fromCallable { ContactUtil.buildAddToContactsIntent(fragment.requireContext(), contact) }
)
}
fun createIntentAndLaunch(
fragment: Fragment,
launcher: ActivityResultLauncher<Intent>,
recipient: Recipient
): Disposable {
return launchIntent(
fragment = fragment,
launcher = launcher,
intentProducer = Single.just(RecipientExporter.export(recipient).asAddContactIntent())
)
}
private fun launchIntent(
fragment: Fragment,
launcher: ActivityResultLauncher<Intent>,
intentProducer: Single<Intent>
): Disposable {
return intentProducer
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribeBy { .subscribeBy {

View File

@@ -74,6 +74,7 @@ import org.signal.libsignal.protocol.InvalidMessageException
import org.thoughtcrime.securesms.BlockUnblockDialog import org.thoughtcrime.securesms.BlockUnblockDialog
import org.thoughtcrime.securesms.LoggingFragment import org.thoughtcrime.securesms.LoggingFragment
import org.thoughtcrime.securesms.MainActivity import org.thoughtcrime.securesms.MainActivity
import org.thoughtcrime.securesms.MuteDialog
import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.badges.gifts.OpenableGift import org.thoughtcrime.securesms.badges.gifts.OpenableGift
import org.thoughtcrime.securesms.badges.gifts.OpenableGiftItemDecoration import org.thoughtcrime.securesms.badges.gifts.OpenableGiftItemDecoration
@@ -1790,7 +1791,13 @@ class ConversationFragment : LoggingFragment(R.layout.v2_conversation_fragment)
} }
override fun handleAddToContacts() { override fun handleAddToContacts() {
// TODO [cfv2] - ("Not yet implemented") val recipient = viewModel.recipientSnapshot?.takeIf { it.isIndividual } ?: return
AddToContactsContract.createIntentAndLaunch(
fragment = this@ConversationFragment,
launcher = addToContactsLauncher,
recipient = recipient
)
} }
override fun handleDisplayGroupRecipients() { override fun handleDisplayGroupRecipients() {
@@ -1842,11 +1849,11 @@ class ConversationFragment : LoggingFragment(R.layout.v2_conversation_fragment)
} }
override fun handleMuteNotifications() { override fun handleMuteNotifications() {
// TODO [cfv2] - ("Not yet implemented") MuteDialog.show(requireContext(), viewModel::muteConversation)
} }
override fun handleUnmuteNotifications() { override fun handleUnmuteNotifications() {
// TODO [cfv2] - ("Not yet implemented") viewModel.muteConversation(0L)
} }
override fun handleConversationSettings() { override fun handleConversationSettings() {

View File

@@ -44,6 +44,7 @@ import org.thoughtcrime.securesms.database.RecipientTable
import org.thoughtcrime.securesms.database.RxDatabaseObserver import org.thoughtcrime.securesms.database.RxDatabaseObserver
import org.thoughtcrime.securesms.database.SignalDatabase import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.database.SignalDatabase.Companion.attachments import org.thoughtcrime.securesms.database.SignalDatabase.Companion.attachments
import org.thoughtcrime.securesms.database.SignalDatabase.Companion.recipients
import org.thoughtcrime.securesms.database.model.GroupRecord import org.thoughtcrime.securesms.database.model.GroupRecord
import org.thoughtcrime.securesms.database.model.IdentityRecord import org.thoughtcrime.securesms.database.model.IdentityRecord
import org.thoughtcrime.securesms.database.model.Mention import org.thoughtcrime.securesms.database.model.Mention
@@ -345,6 +346,10 @@ class ConversationRepository(
}.subscribeOn(Schedulers.io()) }.subscribeOn(Schedulers.io())
} }
fun setConversationMuted(recipientId: RecipientId, until: Long) {
SignalExecutors.BOUNDED_IO.execute { recipients.setMuted(recipientId, until) }
}
/** /**
* Copies the selected content to the clipboard. Maybe will emit either the copied contents or * Copies the selected content to the clipboard. Maybe will emit either the copied contents or
* a complete which means there were no contents to be copied. * a complete which means there were no contents to be copied.

View File

@@ -15,6 +15,7 @@ import io.reactivex.rxjava3.core.Maybe
import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.addTo
import io.reactivex.rxjava3.kotlin.plusAssign import io.reactivex.rxjava3.kotlin.plusAssign
import io.reactivex.rxjava3.kotlin.subscribeBy import io.reactivex.rxjava3.kotlin.subscribeBy
import io.reactivex.rxjava3.processors.PublishProcessor import io.reactivex.rxjava3.processors.PublishProcessor
@@ -221,6 +222,14 @@ class ConversationViewModel(
} }
} }
fun muteConversation(until: Long) {
recipient.firstOrError()
.subscribeBy {
repository.setConversationMuted(it.id, until)
}
.addTo(disposables)
}
fun requestMarkRead(timestamp: Long) { fun requestMarkRead(timestamp: Long) {
} }

View File

@@ -840,6 +840,13 @@ public class Recipient {
return lastProfileFetch; return lastProfileFetch;
} }
/**
* Denotes that this Recipient represents another person.
*/
public boolean isIndividual() {
return !isGroup() && !isCallLink() && !isDistributionList() && !isReleaseNotes();
}
public boolean isGroup() { public boolean isGroup() {
return resolve().groupId != null; return resolve().groupId != null;
} }