From 2803976ee590f2f709b58f4937f3759647103e78 Mon Sep 17 00:00:00 2001 From: Scott Lewis Date: Mon, 17 Feb 2025 16:15:45 -0800 Subject: [PATCH] Impl of sendStoryMessage Signed-off-by: Scott Lewis --- .../asamk/signal/manager/internal/ManagerImpl.java | 10 +++------- src/main/java/org/asamk/Signal.java | 2 -- .../java/org/asamk/signal/commands/SendCommand.java | 11 ++++++++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/src/main/java/org/asamk/signal/manager/internal/ManagerImpl.java b/lib/src/main/java/org/asamk/signal/manager/internal/ManagerImpl.java index f178b3a8..e7874fad 100644 --- a/lib/src/main/java/org/asamk/signal/manager/internal/ManagerImpl.java +++ b/lib/src/main/java/org/asamk/signal/manager/internal/ManagerImpl.java @@ -124,7 +124,6 @@ import org.slf4j.LoggerFactory; import org.whispersystems.signalservice.api.SignalSessionLock; import org.whispersystems.signalservice.api.messages.SignalServiceAttachment; import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage; -import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2; import org.whispersystems.signalservice.api.messages.SignalServicePreview; import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage; import org.whispersystems.signalservice.api.messages.SignalServiceStoryMessage; @@ -148,9 +147,6 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable; import io.reactivex.rxjava3.schedulers.Schedulers; import okio.Utf8; -import static org.asamk.signal.manager.config.ServiceConfig.MAX_MESSAGE_SIZE_BYTES; -import static org.signal.core.util.StringExtensionsKt.splitByByteLength; - public class ManagerImpl implements Manager { private static final Logger logger = LoggerFactory.getLogger(ManagerImpl.class); @@ -757,6 +753,7 @@ public class ManagerImpl implements Manager { return sendMessage(messageBuilder, recipients, notifySelf); } + @Override public SendMessageResults sendStoryMessage(Message message, RecipientIdentifier.Group idGroup ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException, InvalidStickerException { @@ -772,8 +769,8 @@ public class ManagerImpl implements Manager { SignalServiceStoryMessage storyMessage = null; if (attachments != null && attachments.size() > 0) { - SignalServiceAttachment.Builder attachmentBuilder = new SignalServiceAttachment.Builder().withFileName(attachments.get(0)); - storyMessage = SignalServiceStoryMessage.forFileAttachment(profileKey, null, attachmentBuilder.build(), true, bodyRanges); + var attachment = context.getAttachmentHelper().uploadAttachment(attachments.get(0)); + storyMessage = SignalServiceStoryMessage.forFileAttachment(profileKey, null, attachment, true, bodyRanges); } else { //SignalServiceTextAttachment textBuilder = new SignalServiceTextAttachment. //storyMessage = SignalServiceStoryMessage.forTextAttachment(profileKey, ssgroup, textBuilder.build(), true, bodyRanges); @@ -1644,5 +1641,4 @@ public class ManagerImpl implements Manager { account = null; } - } diff --git a/src/main/java/org/asamk/Signal.java b/src/main/java/org/asamk/Signal.java index b74b8383..b896f90b 100644 --- a/src/main/java/org/asamk/Signal.java +++ b/src/main/java/org/asamk/Signal.java @@ -756,6 +756,4 @@ public interface Signal extends DBusInterface { } long sendStoryMessage(String messageText, List attachments, byte[] groupId); - - //long sendStoryMessage(String messageText, List attachments, byte[] groupId); } diff --git a/src/main/java/org/asamk/signal/commands/SendCommand.java b/src/main/java/org/asamk/signal/commands/SendCommand.java index a669596e..13ffcead 100644 --- a/src/main/java/org/asamk/signal/commands/SendCommand.java +++ b/src/main/java/org/asamk/signal/commands/SendCommand.java @@ -124,6 +124,13 @@ public class SendCommand implements JsonRpcLocalCommand { groupIdStrings, usernameStrings); + boolean isStory = false; + + if (recipientIdentifiers.size() > 0 + && recipientIdentifiers.iterator().next() instanceof RecipientIdentifier.Group) { + isStory = Boolean.TRUE.equals(ns.getBoolean("story")); + } + final var isEndSession = Boolean.TRUE.equals(ns.getBoolean("end-session")); if (isEndSession) { final var singleRecipients = recipientIdentifiers.stream() @@ -233,8 +240,6 @@ public class SendCommand implements JsonRpcLocalCommand { final var editTimestamp = ns.getLong("edit-timestamp"); - final boolean story = false; - try { final var message = new Message(messageText, attachments, @@ -246,7 +251,7 @@ public class SendCommand implements JsonRpcLocalCommand { textStyles); var results = editTimestamp != null ? m.sendEditMessage(message, recipientIdentifiers, editTimestamp) - //: story ? // m.sendStoryMessage(message, recipientIdentifiers, notifySelf) + : isStory ? m.sendStoryMessage(message, (RecipientIdentifier.Group) recipientIdentifiers.iterator().next()) : m.sendMessage(message, recipientIdentifiers, notifySelf); outputResult(outputWriter, results); } catch (AttachmentInvalidException | IOException e) {