X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/780c69d80476ced44d643d670f3c3e9359eb26e6..91700ce995ae381dd97b246ea3ff11afb748e421:/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java diff --git a/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java b/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java index 9696d956..6895da63 100644 --- a/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java +++ b/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java @@ -40,6 +40,7 @@ import org.asamk.signal.manager.api.SendMessageResults; import org.asamk.signal.manager.api.StickerPackId; import org.asamk.signal.manager.api.StickerPackInvalidException; import org.asamk.signal.manager.api.StickerPackUrl; +import org.asamk.signal.manager.api.TextStyle; import org.asamk.signal.manager.api.TypingAction; import org.asamk.signal.manager.api.UnregisteredRecipientException; import org.asamk.signal.manager.api.UpdateGroup; @@ -466,6 +467,14 @@ class ManagerImpl implements Manager { private SendMessageResults sendMessage( SignalServiceDataMessage.Builder messageBuilder, Set recipients + ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException { + return sendMessage(messageBuilder, recipients, Optional.empty()); + } + + private SendMessageResults sendMessage( + SignalServiceDataMessage.Builder messageBuilder, + Set recipients, + Optional editTargetTimestamp ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException { var results = new HashMap>(); long timestamp = System.currentTimeMillis(); @@ -474,17 +483,19 @@ class ManagerImpl implements Manager { if (recipient instanceof RecipientIdentifier.Single single) { try { final var recipientId = context.getRecipientHelper().resolveRecipient(single); - final var result = context.getSendHelper().sendMessage(messageBuilder, recipientId); + final var result = context.getSendHelper() + .sendMessage(messageBuilder, recipientId, editTargetTimestamp); results.put(recipient, List.of(toSendMessageResult(result))); } catch (UnregisteredRecipientException e) { results.put(recipient, List.of(SendMessageResult.unregisteredFailure(single.toPartialRecipientAddress()))); } } else if (recipient instanceof RecipientIdentifier.NoteToSelf) { - final var result = context.getSendHelper().sendSelfMessage(messageBuilder); + final var result = context.getSendHelper().sendSelfMessage(messageBuilder, editTargetTimestamp); results.put(recipient, List.of(toSendMessageResult(result))); } else if (recipient instanceof RecipientIdentifier.Group group) { - final var result = context.getSendHelper().sendAsGroupMessage(messageBuilder, group.groupId()); + final var result = context.getSendHelper() + .sendAsGroupMessage(messageBuilder, group.groupId(), editTargetTimestamp); results.put(recipient, result.stream().map(this::toSendMessageResult).toList()); } } @@ -581,6 +592,15 @@ class ManagerImpl implements Manager { return sendMessage(messageBuilder, recipients); } + @Override + public SendMessageResults sendEditMessage( + Message message, Set recipients, long editTargetTimestamp + ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException, InvalidStickerException { + final var messageBuilder = SignalServiceDataMessage.newBuilder(); + applyMessage(messageBuilder, message); + return sendMessage(messageBuilder, recipients, Optional.of(editTargetTimestamp)); + } + private void applyMessage( final SignalServiceDataMessage.Builder messageBuilder, final Message message ) throws AttachmentInvalidException, IOException, UnregisteredRecipientException, InvalidStickerException { @@ -599,6 +619,9 @@ class ManagerImpl implements Manager { if (message.mentions().size() > 0) { messageBuilder.withMentions(resolveMentions(message.mentions())); } + if (message.textStyles().size() > 0) { + messageBuilder.withBodyRanges(message.textStyles().stream().map(TextStyle::toBodyRange).toList()); + } if (message.quote().isPresent()) { final var quote = message.quote().get(); messageBuilder.withQuote(new SignalServiceDataMessage.Quote(quote.timestamp(), @@ -609,7 +632,7 @@ class ManagerImpl implements Manager { List.of(), resolveMentions(quote.mentions()), SignalServiceDataMessage.Quote.Type.NORMAL, - List.of())); + quote.textStyles().stream().map(TextStyle::toBodyRange).toList())); } if (message.sticker().isPresent()) { final var sticker = message.sticker().get();