Implement sending message quotes

Fixes #213
This commit is contained in:
AsamK 2021-11-21 19:18:17 +01:00
parent 415b65d208
commit d13d150fe1
6 changed files with 87 additions and 29 deletions

View file

@ -708,15 +708,27 @@ public class ManagerImpl implements Manager {
messageBuilder.withAttachments(attachmentHelper.uploadAttachments(attachments));
}
if (message.mentions().size() > 0) {
final var mentions = new ArrayList<SignalServiceDataMessage.Mention>();
for (final var m : message.mentions()) {
final var recipientId = resolveRecipient(m.recipient());
mentions.add(new SignalServiceDataMessage.Mention(resolveSignalServiceAddress(recipientId).getAci(),
m.start(),
m.length()));
}
messageBuilder.withMentions(mentions);
messageBuilder.withMentions(resolveMentions(message.mentions()));
}
if (message.quote().isPresent()) {
final var quote = message.quote().get();
messageBuilder.withQuote(new SignalServiceDataMessage.Quote(quote.timestamp(),
resolveSignalServiceAddress(resolveRecipient(quote.author())),
quote.message(),
List.of(),
resolveMentions(quote.mentions())));
}
}
private ArrayList<SignalServiceDataMessage.Mention> resolveMentions(final List<Message.Mention> mentionList) throws IOException {
final var mentions = new ArrayList<SignalServiceDataMessage.Mention>();
for (final var m : mentionList) {
final var recipientId = resolveRecipient(m.recipient());
mentions.add(new SignalServiceDataMessage.Mention(resolveSignalServiceAddress(recipientId).getAci(),
m.start(),
m.length()));
}
return mentions;
}
@Override

View file

@ -1,8 +1,11 @@
package org.asamk.signal.manager.api;
import java.util.List;
import java.util.Optional;
public record Message(String messageText, List<String> attachments, List<Mention> mentions) {
public record Message(String messageText, List<String> attachments, List<Mention> mentions, Optional<Quote> quote) {
public record Mention(RecipientIdentifier.Single recipient, int start, int length) {}
public record Quote(long timestamp, RecipientIdentifier.Single author, String message, List<Mention> mentions) {}
}