mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Add support for scheduled message sends.
This commit is contained in:
@@ -27,7 +27,8 @@ class MediaSendActivityResult(
|
||||
val isViewOnce: Boolean,
|
||||
val mentions: List<Mention>,
|
||||
@TypeParceler<BodyRangeList?, BodyRangeListParceler>() val bodyRanges: BodyRangeList?,
|
||||
val storyType: StoryType
|
||||
val storyType: StoryType,
|
||||
val scheduledTime: Long = -1
|
||||
) : Parcelable {
|
||||
|
||||
val isPushPreUpload: Boolean
|
||||
|
||||
@@ -78,7 +78,8 @@ class MediaSelectionRepository(context: Context) {
|
||||
contacts: List<ContactSearchKey.RecipientSearchKey>,
|
||||
mentions: List<Mention>,
|
||||
bodyRanges: BodyRangeList?,
|
||||
sendType: MessageSendType
|
||||
sendType: MessageSendType,
|
||||
scheduledTime: Long = -1
|
||||
): Maybe<MediaSendActivityResult> {
|
||||
if (isSms && contacts.isNotEmpty()) {
|
||||
throw IllegalStateException("Provided recipients to send to, but this is SMS!")
|
||||
@@ -112,8 +113,8 @@ class MediaSelectionRepository(context: Context) {
|
||||
StoryType.NONE
|
||||
}
|
||||
|
||||
if (isSms || MessageSender.isLocalSelfSend(context, singleRecipient, MessageSender.SendType.SIGNAL)) {
|
||||
Log.i(TAG, "SMS or local self-send. Skipping pre-upload.")
|
||||
if (isSms || MessageSender.isLocalSelfSend(context, singleRecipient, MessageSender.SendType.SIGNAL) || (scheduledTime != -1L && storyType == StoryType.NONE)) {
|
||||
Log.i(TAG, "SMS, local self-send, or scheduled send. Skipping pre-upload.")
|
||||
emitter.onSuccess(
|
||||
MediaSendActivityResult(
|
||||
recipientId = singleRecipient!!.id,
|
||||
@@ -123,7 +124,8 @@ class MediaSelectionRepository(context: Context) {
|
||||
isViewOnce = isViewOnce,
|
||||
mentions = trimmedMentions,
|
||||
bodyRanges = trimmedBodyRanges,
|
||||
storyType = StoryType.NONE
|
||||
storyType = StoryType.NONE,
|
||||
scheduledTime = scheduledTime
|
||||
)
|
||||
)
|
||||
} else {
|
||||
|
||||
@@ -333,7 +333,13 @@ class MediaSelectionViewModel(
|
||||
}
|
||||
|
||||
fun send(
|
||||
selectedContacts: List<ContactSearchKey.RecipientSearchKey> = emptyList()
|
||||
selectedContacts: List<ContactSearchKey.RecipientSearchKey> = emptyList(),
|
||||
scheduledDate: Long? = null
|
||||
): Maybe<MediaSendActivityResult> = send(selectedContacts, scheduledDate ?: -1)
|
||||
|
||||
fun send(
|
||||
selectedContacts: List<ContactSearchKey.RecipientSearchKey> = emptyList(),
|
||||
scheduledDate: Long
|
||||
): Maybe<MediaSendActivityResult> {
|
||||
return UntrustedRecords.checkForBadIdentityRecords(selectedContacts.toSet(), identityChangesSince).andThen(
|
||||
repository.send(
|
||||
@@ -347,7 +353,8 @@ class MediaSelectionViewModel(
|
||||
contacts = selectedContacts.ifEmpty { destination.getRecipientSearchKeyList() },
|
||||
mentions = MentionAnnotation.getMentionsFromAnnotations(store.state.message),
|
||||
bodyRanges = MessageStyler.getStyling(store.state.message),
|
||||
sendType = store.state.sendType
|
||||
sendType = store.state.sendType,
|
||||
scheduledTime = scheduledDate
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.TextView
|
||||
@@ -29,6 +30,8 @@ import org.signal.core.util.concurrent.SimpleTask
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.contacts.paged.ContactSearchKey
|
||||
import org.thoughtcrime.securesms.conversation.MessageSendType
|
||||
import org.thoughtcrime.securesms.conversation.ScheduleMessageContextMenu
|
||||
import org.thoughtcrime.securesms.conversation.ScheduleMessageTimePickerBottomSheet
|
||||
import org.thoughtcrime.securesms.conversation.mutiselect.forward.MultiselectForwardActivity
|
||||
import org.thoughtcrime.securesms.conversation.mutiselect.forward.MultiselectForwardFragmentArgs
|
||||
import org.thoughtcrime.securesms.mediasend.MediaSendActivityResult
|
||||
@@ -44,6 +47,7 @@ import org.thoughtcrime.securesms.mms.SentMediaQuality
|
||||
import org.thoughtcrime.securesms.permissions.Permissions
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.scribbles.ImageEditorFragment
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags
|
||||
import org.thoughtcrime.securesms.util.LifecycleDisposable
|
||||
import org.thoughtcrime.securesms.util.MediaUtil
|
||||
import org.thoughtcrime.securesms.util.SystemWindowInsetsSetter
|
||||
@@ -55,7 +59,7 @@ import org.thoughtcrime.securesms.util.visible
|
||||
/**
|
||||
* Allows the user to view and edit selected media.
|
||||
*/
|
||||
class MediaReviewFragment : Fragment(R.layout.v2_media_review_fragment) {
|
||||
class MediaReviewFragment : Fragment(R.layout.v2_media_review_fragment), ScheduleMessageTimePickerBottomSheet.ScheduleCallback {
|
||||
|
||||
private val sharedViewModel: MediaSelectionViewModel by viewModels(
|
||||
ownerProducer = { requireActivity() }
|
||||
@@ -88,6 +92,8 @@ class MediaReviewFragment : Fragment(R.layout.v2_media_review_fragment) {
|
||||
private var animatorSet: AnimatorSet? = null
|
||||
private var disposables: LifecycleDisposable = LifecycleDisposable()
|
||||
|
||||
private var scheduledSendTime: Long? = null
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
postponeEnterTransition()
|
||||
|
||||
@@ -198,6 +204,7 @@ class MediaReviewFragment : Fragment(R.layout.v2_media_review_fragment) {
|
||||
} else {
|
||||
storiesLauncher.launch(StoriesMultiselectForwardActivity.Args(args, emptyList()))
|
||||
}
|
||||
scheduledSendTime = null
|
||||
} else {
|
||||
multiselectLauncher.launch(args)
|
||||
}
|
||||
@@ -207,10 +214,25 @@ class MediaReviewFragment : Fragment(R.layout.v2_media_review_fragment) {
|
||||
.setPositiveButton(R.string.MediaReviewFragment__add_to_story) { _, _ -> performSend() }
|
||||
.setNegativeButton(android.R.string.cancel) { _, _ -> }
|
||||
.show()
|
||||
scheduledSendTime = null
|
||||
} else {
|
||||
performSend()
|
||||
}
|
||||
}
|
||||
if (FeatureFlags.scheduledMessageSends()) {
|
||||
sendButton.setOnLongClickListener {
|
||||
ScheduleMessageContextMenu.show(it, (requireView() as ViewGroup)) { time: Long ->
|
||||
if (time == -1L) {
|
||||
scheduledSendTime = null
|
||||
ScheduleMessageTimePickerBottomSheet.showSchedule(childFragmentManager)
|
||||
} else {
|
||||
scheduledSendTime = time
|
||||
sendButton.performClick()
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
addMediaButton.setOnClickListener {
|
||||
launchGallery()
|
||||
@@ -325,7 +347,7 @@ class MediaReviewFragment : Fragment(R.layout.v2_media_review_fragment) {
|
||||
.alpha(1f)
|
||||
|
||||
disposables += sharedViewModel
|
||||
.send(selection.filterIsInstance(ContactSearchKey.RecipientSearchKey::class.java))
|
||||
.send(selection.filterIsInstance(ContactSearchKey.RecipientSearchKey::class.java), scheduledSendTime)
|
||||
.subscribe(
|
||||
{ result -> callback.onSentWithResult(result) },
|
||||
{ error -> callback.onSendError(error) },
|
||||
@@ -560,4 +582,9 @@ class MediaReviewFragment : Fragment(R.layout.v2_media_review_fragment) {
|
||||
fun onNoMediaSelected()
|
||||
fun onPopFromReview()
|
||||
}
|
||||
|
||||
override fun onScheduleSend(scheduledTime: Long) {
|
||||
scheduledSendTime = scheduledTime
|
||||
sendButton.performClick()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user