Ensure SMS and MMS messages are sent appropriately.

This commit is contained in:
Greyson Parrelli
2023-01-06 11:27:33 -05:00
parent 5537039e46
commit e2fb65920c
18 changed files with 70 additions and 42 deletions

View File

@@ -254,7 +254,7 @@ public class InviteActivity extends PassphraseRequiredActivity implements Contac
Recipient recipient = Recipient.resolved(recipientId);
int subscriptionId = recipient.getDefaultSubscriptionId().orElse(-1);
MessageSender.send(context, OutgoingMessage.sms(recipient, message, subscriptionId), -1L, true, null, null);
MessageSender.send(context, OutgoingMessage.sms(recipient, message, subscriptionId), -1L, MessageSender.SendType.SMS, null, null);
if (recipient.getContactUri() != null) {
SignalDatabase.recipients().setHasSentInvite(recipient.getId());

View File

@@ -40,7 +40,7 @@ class ExpireTimerSettingsRepository(val context: Context) {
} else {
SignalDatabase.recipients.setExpireMessages(recipientId, newExpirationTime)
val outgoingMessage = OutgoingMessage.expirationUpdateMessage(Recipient.resolved(recipientId), System.currentTimeMillis(), newExpirationTime * 1000L)
MessageSender.send(context, outgoingMessage, getThreadId(recipientId), false, null, null)
MessageSender.send(context, outgoingMessage, getThreadId(recipientId), MessageSender.SendType.SIGNAL, null, null)
consumer.invoke(Result.success(newExpirationTime))
}
}

View File

@@ -267,6 +267,7 @@ import org.thoughtcrime.securesms.safety.SafetyNumberBottomSheet;
import org.thoughtcrime.securesms.search.MessageResult;
import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.sms.MessageSender;
import org.thoughtcrime.securesms.sms.MessageSender.SendType;
import org.thoughtcrime.securesms.stickers.StickerEventListener;
import org.thoughtcrime.securesms.stickers.StickerLocator;
import org.thoughtcrime.securesms.stickers.StickerManagementActivity;
@@ -3113,7 +3114,7 @@ public class ConversationParentFragment extends Fragment
final long id = fragment.stageOutgoingMessage(outgoingMessage);
SimpleTask.run(() -> {
return MessageSender.send(context, outgoingMessage, thread, sendType.usesSmsTransport(), metricId, null);
return MessageSender.send(context, outgoingMessage, thread, sendType.usesSmsTransport() ? SendType.MMS : SendType.SIGNAL, metricId, null);
}, result -> {
sendComplete(result);
future.set(null);
@@ -3153,7 +3154,7 @@ public class ConversationParentFragment extends Fragment
.withPermanentDenialDialog(getString(R.string.ConversationActivity_signal_needs_sms_permission_in_order_to_send_an_sms))
.onAllGranted(() -> {
SimpleTask.run(() -> {
return MessageSender.send(context, message, thread, sendType.usesSmsTransport(), metricId, null);
return MessageSender.send(context, message, thread, sendType.usesSmsTransport() ? SendType.SMS : SendType.SIGNAL, metricId, null);
}, this::sendComplete);
silentlySetComposeText("");

View File

@@ -185,7 +185,7 @@ final class GroupManagerV1 {
Collections.emptyList(),
Collections.emptyList());
long threadId = MessageSender.send(context, outgoingMessage, -1, false, null, null);
long threadId = MessageSender.send(context, outgoingMessage, -1, MessageSender.SendType.SIGNAL, null, null);
return new GroupActionResult(groupRecipient, threadId, newMemberCount, Collections.emptyList());
}
@@ -209,7 +209,7 @@ final class GroupManagerV1 {
recipientTable.setExpireMessages(recipient.getId(), expirationTime);
OutgoingMessage outgoingMessage = OutgoingMessage.expirationUpdateMessage(recipient, System.currentTimeMillis(), expirationTime * 1000L);
MessageSender.send(context, outgoingMessage, threadId, false, null, null);
MessageSender.send(context, outgoingMessage, threadId, MessageSender.SendType.SIGNAL, null, null);
}
@WorkerThread

View File

@@ -1279,7 +1279,7 @@ final class GroupManagerV2 {
} else {
//noinspection IfStatementWithIdenticalBranches
if (sendToMembers) {
long threadId = MessageSender.send(context, outgoingMessage, -1, false, null, null);
long threadId = MessageSender.send(context, outgoingMessage, -1, MessageSender.SendType.SIGNAL, null, null);
return new RecipientAndThread(groupRecipient, threadId);
} else {
long threadId = SignalDatabase.threads().getOrCreateValidThreadId(outgoingMessage.getRecipient(), -1, outgoingMessage.getDistributionType());

View File

@@ -78,7 +78,7 @@ public class InsightsRepository implements InsightsDashboardViewModel.Repository
int subscriptionId = resolved.getDefaultSubscriptionId().orElse(-1);
String message = context.getString(R.string.InviteActivity_lets_switch_to_signal, context.getString(R.string.install_url));
MessageSender.send(context, OutgoingMessage.sms(resolved, message, subscriptionId), -1L, true, null, null);
MessageSender.send(context, OutgoingMessage.sms(resolved, message, subscriptionId), -1L, MessageSender.SendType.SMS, null, null);
RecipientTable database = SignalDatabase.recipients();
database.setHasSentInvite(recipient.getId());

View File

@@ -68,7 +68,7 @@ class GiftSendJob private constructor(parameters: Parameters, private val recipi
Log.i(TAG, "Sending gift badge to $recipientId...")
var didInsert = false
MessageSender.send(context, outgoingMessage, thread, false, null) {
MessageSender.send(context, outgoingMessage, thread, MessageSender.SendType.SIGNAL, null) {
didInsert = true
}

View File

@@ -70,7 +70,7 @@ class PaymentNotificationSendJobV2 private constructor(
recipient.expiresInSeconds.seconds.inWholeMilliseconds
),
SignalDatabase.threads.getOrCreateThreadIdFor(recipient),
false,
MessageSender.SendType.SIGNAL,
null,
null
)

View File

@@ -47,7 +47,7 @@ class SendPaymentsActivatedJob(parameters: Parameters) : BaseJob(parameters) {
context,
OutgoingMessage.paymentsActivatedMessage(recipient, System.currentTimeMillis(), 0),
threadId,
false,
MessageSender.SendType.SIGNAL,
null,
null
)

View File

@@ -109,7 +109,7 @@ class MediaSelectionRepository(context: Context) {
StoryType.NONE
}
if (isSms || MessageSender.isLocalSelfSend(context, singleRecipient, isSms)) {
if (isSms || MessageSender.isLocalSelfSend(context, singleRecipient, MessageSender.SendType.SIGNAL)) {
Log.i(TAG, "SMS or local self-send. Skipping pre-upload.")
emitter.onSuccess(MediaSendActivityResult.forTraditionalSend(singleRecipient!!.id, updatedMedia, trimmedBody, sendType, isViewOnce, trimmedMentions, StoryType.NONE))
} else {
@@ -182,7 +182,7 @@ class MediaSelectionRepository(context: Context) {
}
fun isLocalSelfSend(recipient: Recipient?, isSms: Boolean): Boolean {
return MessageSender.isLocalSelfSend(context, recipient, isSms)
return MessageSender.isLocalSelfSend(context, recipient, if (isSms) MessageSender.SendType.SMS else MessageSender.SendType.SIGNAL)
}
@WorkerThread

View File

@@ -464,7 +464,7 @@ public class AttachmentManager {
.setMessage(context.getString(R.string.AttachmentManager__request_to_activate_payments))
.setPositiveButton(context.getString(R.string.AttachmentManager__send_request), (dialog, which) -> {
OutgoingMessage outgoingMessage = OutgoingMessage.requestToActivatePaymentsMessage(recipient, System.currentTimeMillis(), 0);
MessageSender.send(context, outgoingMessage, SignalDatabase.threads().getOrCreateThreadIdFor(recipient), false, null, null);
MessageSender.send(context, outgoingMessage, SignalDatabase.threads().getOrCreateThreadIdFor(recipient), MessageSender.SendType.SIGNAL, null, null);
})
.setNegativeButton(context.getString(R.string.AttachmentManager__cancel), null)
.show();

View File

@@ -101,17 +101,17 @@ public class RemoteReplyReceiver extends BroadcastReceiver {
Collections.emptySet(),
null,
recipient.isPushGroup());
threadId = MessageSender.send(context, reply, -1, false, null, null);
threadId = MessageSender.send(context, reply, -1, MessageSender.SendType.SIGNAL, null, null);
break;
}
case SecureMessage: {
OutgoingMessage reply = OutgoingMessage.text(recipient, responseText.toString(), expiresIn, System.currentTimeMillis());
threadId = MessageSender.send(context, reply, -1, false, null, null);
threadId = MessageSender.send(context, reply, -1, MessageSender.SendType.SIGNAL, null, null);
break;
}
case UnsecuredSmsMessage: {
OutgoingMessage reply = OutgoingMessage.sms(recipient, responseText.toString(), subscriptionId);
threadId = MessageSender.send(context, reply, -1, true, null, null);
threadId = MessageSender.send(context, reply, -1, MessageSender.SendType.SMS, null, null);
break;
}
default:

View File

@@ -321,7 +321,7 @@ public class RecipientUtil {
if (threadId == -1 || !SignalDatabase.messages().hasMeaningfulMessage(threadId)) {
SignalDatabase.recipients().setExpireMessages(recipient.getId(), defaultTimer);
OutgoingMessage outgoingMessage = OutgoingMessage.expirationUpdateMessage(recipient, System.currentTimeMillis(), defaultTimer * 1000L);
MessageSender.send(context, outgoingMessage, SignalDatabase.threads().getOrCreateThreadIdFor(recipient), false, null, null);
MessageSender.send(context, outgoingMessage, SignalDatabase.threads().getOrCreateThreadIdFor(recipient), MessageSender.SendType.SIGNAL, null, null);
return true;
}
return false;

View File

@@ -50,7 +50,7 @@ public class QuickResponseService extends IntentService {
int subscriptionId = recipient.getDefaultSubscriptionId().orElse(-1);
if (!TextUtils.isEmpty(content)) {
MessageSender.send(this, OutgoingMessage.sms(recipient, content, subscriptionId), -1, false, null, null);
MessageSender.send(this, OutgoingMessage.sms(recipient, content, subscriptionId), -1, MessageSender.SendType.SIGNAL, null, null);
}
} catch (URISyntaxException e) {
Toast.makeText(this, R.string.QuickResponseService_problem_sending_message, Toast.LENGTH_LONG).show();

View File

@@ -43,6 +43,7 @@ import org.thoughtcrime.securesms.mms.VideoSlide;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.sms.MessageSender;
import org.thoughtcrime.securesms.sms.MessageSender.SendType;
import org.thoughtcrime.securesms.stories.Stories;
import org.thoughtcrime.securesms.util.Base64;
import org.thoughtcrime.securesms.util.MediaUtil;
@@ -307,11 +308,11 @@ public final class MultiShareSender {
storiesToBatchSend.addAll(outgoingMessages);
} else if (shouldSendAsPush(recipient, forceSms)) {
for (final OutgoingMessage outgoingMessage : outgoingMessages) {
MessageSender.send(context, outgoingMessage.makeSecure(), threadId, false, null, null);
MessageSender.send(context, outgoingMessage.makeSecure(), threadId, SendType.SIGNAL, null, null);
}
} else {
for (final OutgoingMessage outgoingMessage : outgoingMessages) {
MessageSender.send(context, outgoingMessage, threadId, forceSms, null, null);
MessageSender.send(context, outgoingMessage, threadId, SendType.MMS, null, null);
}
}
}
@@ -393,7 +394,7 @@ public final class MultiShareSender {
outgoingMessage = OutgoingMessage.sms(recipient, body, subscriptionId);
}
MessageSender.send(context, outgoingMessage, threadId, forceSms, null, null);
MessageSender.send(context, outgoingMessage, threadId, forceSms ? SendType.SMS : SendType.SIGNAL, null, null);
}
private static @NonNull OutgoingMessage generateTextStory(@NonNull Context context,

View File

@@ -60,6 +60,7 @@ import org.thoughtcrime.securesms.jobs.IndividualSendJob;
import org.thoughtcrime.securesms.jobs.ReactionSendJob;
import org.thoughtcrime.securesms.jobs.RemoteDeleteSendJob;
import org.thoughtcrime.securesms.jobs.ResumableUploadSpecJob;
import org.thoughtcrime.securesms.jobs.SmsSendJob;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
import org.thoughtcrime.securesms.mediasend.Media;
@@ -201,11 +202,11 @@ public class MessageSender {
List<String> jobDependencyIds = (dependencies != null) ? dependencies.stream().map(UploadDependencyGraph.Node::getJobId).collect(Collectors.toList())
: Collections.emptyList();
sendMediaMessage(context,
recipient,
false,
messageId,
jobDependencyIds);
sendMessageInternal(context,
recipient,
SendType.SIGNAL,
messageId,
jobDependencyIds);
}
onMessageSent();
@@ -218,7 +219,7 @@ public class MessageSender {
public static long send(final Context context,
final OutgoingMessage message,
final long threadId,
final boolean forceSms,
@NonNull SendType sendType,
@Nullable final String metricId,
@Nullable final MessageTable.InsertListener insertListener)
{
@@ -229,7 +230,7 @@ public class MessageSender {
long allocatedThreadId = threadTable.getOrCreateValidThreadId(message.getRecipient(), threadId, message.getDistributionType());
Recipient recipient = message.getRecipient();
long messageId = database.insertMessageOutbox(applyUniversalExpireTimerIfNecessary(context, recipient, message, allocatedThreadId), allocatedThreadId, forceSms, insertListener);
long messageId = database.insertMessageOutbox(applyUniversalExpireTimerIfNecessary(context, recipient, message, allocatedThreadId), allocatedThreadId, sendType != SendType.SIGNAL, insertListener);
if (message.getRecipient().isGroup() && message.getAttachments().isEmpty() && message.getLinkPreviews().isEmpty() && message.getSharedContacts().isEmpty()) {
SignalLocalMetrics.GroupMessageSend.onInsertedIntoDatabase(messageId, metricId);
@@ -237,7 +238,7 @@ public class MessageSender {
SignalLocalMetrics.GroupMessageSend.cancel(metricId);
}
sendMediaMessage(context, recipient, forceSms, messageId, Collections.emptyList());
sendMessageInternal(context, recipient, sendType, messageId, Collections.emptyList());
onMessageSent();
threadTable.update(allocatedThreadId, true);
@@ -274,7 +275,7 @@ public class MessageSender {
attachmentDatabase.updateMessageId(attachmentIds, messageId, message.getStoryType().isStory());
sendMediaMessage(context, recipient, false, messageId, jobIds);
sendMessageInternal(context, recipient, SendType.SIGNAL, messageId, jobIds);
onMessageSent();
threadTable.update(allocatedThreadId, true);
@@ -390,7 +391,7 @@ public class MessageSender {
long messageId = messageIds.get(i);
Recipient recipient = messages.get(i).getRecipient();
if (isLocalSelfSend(context, recipient, false)) {
if (isLocalSelfSend(context, recipient, SendType.SIGNAL)) {
sendLocalMediaSelf(context, messageId);
} else if (recipient.isPushGroup()) {
jobManager.add(new PushGroupSendJob(messageId, recipient.getId(), Collections.emptySet(), true), messageDependsOnIds, recipient.getId().toQueueKey());
@@ -407,7 +408,7 @@ public class MessageSender {
* be enqueued (like in the case of a local self-send).
*/
public static @Nullable PreUploadResult preUploadPushAttachment(@NonNull Context context, @NonNull Attachment attachment, @Nullable Recipient recipient, @NonNull Media media) {
if (isLocalSelfSend(context, recipient, false)) {
if (isLocalSelfSend(context, recipient, SendType.SIGNAL)) {
return null;
}
Log.i(TAG, "Pre-uploading attachment for " + (recipient != null ? recipient.getId() : "null"));
@@ -488,7 +489,21 @@ public class MessageSender {
boolean forceSms = messageRecord.isForcedSms();
Recipient recipient = messageRecord.getRecipient();
sendMediaMessage(context, recipient, forceSms, messageId, Collections.emptyList());
SendType sendType;
if (forceSms) {
Recipient threadRecipient = SignalDatabase.threads().getRecipientForThreadId(messageRecord.getThreadId());
if ((threadRecipient != null && threadRecipient.isGroup()) || SignalDatabase.attachments().getAttachmentsForMessage(messageId).size() > 0) {
sendType = SendType.MMS;
} else {
sendType = SendType.SMS;
}
} else {
sendType = SendType.SIGNAL;
}
sendMessageInternal(context, recipient, sendType, messageId, Collections.emptyList());
onMessageSent();
}
@@ -504,18 +519,20 @@ public class MessageSender {
return outgoingMessage;
}
private static void sendMediaMessage(Context context, Recipient recipient, boolean forceSms, long messageId, @NonNull Collection<String> uploadJobIds)
private static void sendMessageInternal(Context context, Recipient recipient, SendType sendType, long messageId, @NonNull Collection<String> uploadJobIds)
{
if (isLocalSelfSend(context, recipient, forceSms)) {
if (isLocalSelfSend(context, recipient, sendType)) {
sendLocalMediaSelf(context, messageId);
} else if (recipient.isPushGroup()) {
sendGroupPush(context, recipient, messageId, Collections.emptySet(), uploadJobIds);
} else if (recipient.isDistributionList()) {
sendDistributionList(context, recipient, messageId, Collections.emptySet(), uploadJobIds);
} else if (!forceSms && isPushMediaSend(context, recipient)) {
} else if (sendType == SendType.SIGNAL && isPushMediaSend(context, recipient)) {
sendMediaPush(context, recipient, messageId, uploadJobIds);
} else {
} else if (sendType == SendType.MMS) {
sendMms(context, messageId);
} else {
sendSms(recipient, messageId);
}
}
@@ -557,6 +574,11 @@ public class MessageSender {
MmsSendJob.enqueue(context, jobManager, messageId);
}
private static void sendSms(Recipient recipient, long messageId) {
JobManager jobManager = ApplicationDependencies.getJobManager();
jobManager.add(new SmsSendJob(messageId, recipient));
}
private static boolean isPushMediaSend(Context context, Recipient recipient) {
if (!SignalStore.account().isRegistered()) {
return false;
@@ -585,10 +607,10 @@ public class MessageSender {
}
}
public static boolean isLocalSelfSend(@NonNull Context context, @Nullable Recipient recipient, boolean forceSms) {
public static boolean isLocalSelfSend(@NonNull Context context, @Nullable Recipient recipient, SendType sendType) {
return recipient != null &&
recipient.isSelf() &&
!forceSms &&
sendType == SendType.SIGNAL &&
SignalStore.account().isRegistered() &&
!TextSecurePreferences.isMultiDevice(context);
}
@@ -705,4 +727,8 @@ public class MessageSender {
public enum MessageSentEvent {
INSTANCE
}
public enum SendType {
SIGNAL, SMS, MMS
}
}

View File

@@ -64,7 +64,7 @@ class StoryDirectReplyRepository(context: Context) {
null
),
threadId,
false,
MessageSender.SendType.SIGNAL,
null
) {
emitter.onComplete()

View File

@@ -53,7 +53,7 @@ object StoryGroupReplySender {
isSecure = true
),
message.threadId,
false,
MessageSender.SendType.SIGNAL,
null
) {
it.onComplete()