Allow long text to be sent via notification replies.

This commit is contained in:
Cody Henthorne
2025-04-09 09:11:04 -04:00
committed by Michelle Tang
parent 5bce2884a7
commit acbab9e736
2 changed files with 38 additions and 36 deletions

View File

@@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.database.model.databaseprotos.MessageExtras
import org.thoughtcrime.securesms.linkpreview.LinkPreview
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.sms.GroupV2UpdateMessageUtil
import kotlin.time.Duration.Companion.seconds
/**
* Represents all the data needed for an outgoing message.
@@ -469,6 +470,24 @@ data class OutgoingMessage(
)
}
@JvmStatic
fun quickReply(
threadRecipient: Recipient,
slideDeck: SlideDeck?,
body: String,
parentStoryId: ParentStoryId?
): OutgoingMessage {
return OutgoingMessage(
threadRecipient = threadRecipient,
sentTimeMillis = System.currentTimeMillis(),
expiresIn = threadRecipient.expiresInSeconds.seconds.inWholeMilliseconds,
attachments = slideDeck?.asAttachments() ?: emptyList(),
body = body,
parentStoryId = parentStoryId,
isSecure = true
)
}
@JvmStatic
fun buildMessage(slideDeck: SlideDeck, message: String): String {
return if (message.isNotEmpty() && slideDeck.body.isNotEmpty()) {

View File

@@ -29,19 +29,17 @@ import org.signal.core.util.concurrent.SignalExecutors;
import org.thoughtcrime.securesms.database.MessageTable.MarkedMessageInfo;
import org.thoughtcrime.securesms.database.SignalDatabase;
import org.thoughtcrime.securesms.database.model.ParentStoryId;
import org.thoughtcrime.securesms.database.model.StoryType;
import org.thoughtcrime.securesms.dependencies.AppDependencies;
import org.thoughtcrime.securesms.mms.OutgoingMessage;
import org.thoughtcrime.securesms.notifications.v2.DefaultMessageNotifier;
import org.thoughtcrime.securesms.mms.SlideDeck;
import org.thoughtcrime.securesms.notifications.v2.ConversationId;
import org.thoughtcrime.securesms.notifications.v2.DefaultMessageNotifier;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.sms.MessageSender;
import org.thoughtcrime.securesms.util.MessageUtil;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* Get the response text from the Wearable Device and sends an message as a reply
@@ -75,40 +73,25 @@ public class RemoteReplyReceiver extends BroadcastReceiver {
SignalExecutors.BOUNDED.execute(() -> {
long threadId;
Recipient recipient = Recipient.resolved(recipientId);
long expiresIn = TimeUnit.SECONDS.toMillis(recipient.getExpiresInSeconds());
int expireTimerVersion = recipient.getExpireTimerVersion();
ParentStoryId parentStoryId = groupStoryId != Long.MIN_VALUE ? ParentStoryId.deserialize(groupStoryId) : null;
Recipient recipient = Recipient.resolved(recipientId);
String body = responseText.toString();
ParentStoryId parentStoryId = groupStoryId != Long.MIN_VALUE ? ParentStoryId.deserialize(groupStoryId) : null;
MessageUtil.SplitResult splitMessage = MessageUtil.getSplitMessage(context, body);
SlideDeck slideDeck = null;
if (splitMessage.getTextSlide().isPresent()) {
slideDeck = new SlideDeck();
slideDeck.addSlide(splitMessage.getTextSlide().get());
}
switch (replyMethod) {
case SecureMessage:
case GroupMessage: {
OutgoingMessage reply = new OutgoingMessage(recipient,
responseText.toString(),
new LinkedList<>(),
System.currentTimeMillis(),
expiresIn,
expireTimerVersion,
false,
0,
StoryType.NONE,
parentStoryId,
false,
null,
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(),
Collections.emptySet(),
Collections.emptySet(),
null,
recipient.isPushGroup(),
null,
-1,
0);
threadId = MessageSender.send(context, reply, -1, MessageSender.SendType.SIGNAL, null, null);
break;
}
case SecureMessage: {
OutgoingMessage reply = OutgoingMessage.text(recipient, responseText.toString(), expiresIn, System.currentTimeMillis(), null);
OutgoingMessage reply = OutgoingMessage.quickReply(recipient,
slideDeck,
splitMessage.getBody(),
parentStoryId);
threadId = MessageSender.send(context, reply, -1, MessageSender.SendType.SIGNAL, null, null);
break;
}