mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 12:38:33 +00:00
CFV2 -- Add to Contacts / Mute Conversation.
This commit is contained in:
committed by
Cody Henthorne
parent
045d2cf42f
commit
be01f2b511
@@ -18,6 +18,8 @@ import org.thoughtcrime.securesms.contactshare.Contact
|
||||
import org.thoughtcrime.securesms.contactshare.ContactUtil
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
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
|
||||
@@ -44,7 +46,31 @@ class AddToContactsContract : ActivityResultContract<Intent, Unit>() {
|
||||
launcher: ActivityResultLauncher<Intent>,
|
||||
contact: Contact
|
||||
): 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())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeBy {
|
||||
|
||||
@@ -74,6 +74,7 @@ import org.signal.libsignal.protocol.InvalidMessageException
|
||||
import org.thoughtcrime.securesms.BlockUnblockDialog
|
||||
import org.thoughtcrime.securesms.LoggingFragment
|
||||
import org.thoughtcrime.securesms.MainActivity
|
||||
import org.thoughtcrime.securesms.MuteDialog
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.badges.gifts.OpenableGift
|
||||
import org.thoughtcrime.securesms.badges.gifts.OpenableGiftItemDecoration
|
||||
@@ -1790,7 +1791,13 @@ class ConversationFragment : LoggingFragment(R.layout.v2_conversation_fragment)
|
||||
}
|
||||
|
||||
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() {
|
||||
@@ -1842,11 +1849,11 @@ class ConversationFragment : LoggingFragment(R.layout.v2_conversation_fragment)
|
||||
}
|
||||
|
||||
override fun handleMuteNotifications() {
|
||||
// TODO [cfv2] - ("Not yet implemented")
|
||||
MuteDialog.show(requireContext(), viewModel::muteConversation)
|
||||
}
|
||||
|
||||
override fun handleUnmuteNotifications() {
|
||||
// TODO [cfv2] - ("Not yet implemented")
|
||||
viewModel.muteConversation(0L)
|
||||
}
|
||||
|
||||
override fun handleConversationSettings() {
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.thoughtcrime.securesms.database.RecipientTable
|
||||
import org.thoughtcrime.securesms.database.RxDatabaseObserver
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
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.IdentityRecord
|
||||
import org.thoughtcrime.securesms.database.model.Mention
|
||||
@@ -345,6 +346,10 @@ class ConversationRepository(
|
||||
}.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
|
||||
* a complete which means there were no contents to be copied.
|
||||
|
||||
@@ -15,6 +15,7 @@ import io.reactivex.rxjava3.core.Maybe
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.addTo
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import io.reactivex.rxjava3.kotlin.subscribeBy
|
||||
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) {
|
||||
}
|
||||
|
||||
|
||||
@@ -840,6 +840,13 @@ public class Recipient {
|
||||
return lastProfileFetch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Denotes that this Recipient represents another person.
|
||||
*/
|
||||
public boolean isIndividual() {
|
||||
return !isGroup() && !isCallLink() && !isDistributionList() && !isReleaseNotes();
|
||||
}
|
||||
|
||||
public boolean isGroup() {
|
||||
return resolve().groupId != null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user