import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collectors;
public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (syncMessage.sent().isPresent()) {
var transcript = syncMessage.sent().get();
- if (transcript.destination().isPresent() || transcript.message().groupContext().isPresent()) {
- var message = transcript.message();
- var groupId = message.groupContext()
- .map(MessageEnvelope.Data.GroupContext::groupId)
- .map(GroupId::serialize)
- .orElseGet(() -> new byte[0]);
-
- conn.sendMessage(new Signal.SyncMessageReceived(objectPath,
- transcript.message().timestamp(),
- senderString,
- transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""),
- groupId,
- message.body().orElse(""),
- getAttachments(message)));
- conn.sendMessage(new Signal.SyncMessageReceivedV2(objectPath,
- transcript.message().timestamp(),
- senderString,
- transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""),
- groupId,
- message.body().orElse(""),
- getMessageExtras(message)));
+ if (transcript.message().isPresent()) {
+ final var dataMessage = transcript.message().get();
+ if (transcript.destination().isPresent() || dataMessage.groupContext().isPresent()) {
+ var groupId = dataMessage.groupContext()
+ .map(MessageEnvelope.Data.GroupContext::groupId)
+ .map(GroupId::serialize)
+ .orElseGet(() -> new byte[0]);
+
+ conn.sendMessage(new Signal.SyncMessageReceived(objectPath,
+ dataMessage.timestamp(),
+ senderString,
+ transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""),
+ groupId,
+ dataMessage.body().orElse(""),
+ getAttachments(dataMessage)));
+ conn.sendMessage(new Signal.SyncMessageReceivedV2(objectPath,
+ dataMessage.timestamp(),
+ senderString,
+ transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""),
+ groupId,
+ dataMessage.body().orElse(""),
+ getMessageExtras(dataMessage)));
+ }
}
}
}
.stream()
.filter(a -> a.id().isPresent())
.map(this::getAttachmentMap)
- .collect(Collectors.toList());
+ .toList();
extras.put("attachments", new Variant<>(attachments, "aa{sv}"));
}
if (message.mentions().size() > 0) {
- var mentions = message.mentions().stream().map(this::getMentionMap).collect(Collectors.toList());
+ var mentions = message.mentions().stream().map(this::getMentionMap).toList();
extras.put("mentions", new Variant<>(mentions, "aa{sv}"));
}
extras.put("expiresInSeconds", new Variant<>(message.expiresInSeconds()));
}
private Map<String, Variant<? extends Serializable>> getStickerMap(final MessageEnvelope.Data.Sticker sticker) {
- return Map.of("packId", new Variant<>(sticker.packId()), "stickerId", new Variant<>(sticker.stickerId()));
+ return Map.of("packId",
+ new Variant<>(sticker.packId().serialize()),
+ "stickerId",
+ new Variant<>(sticker.stickerId()));
}
private Map<String, Variant<?>> getReactionMap(final MessageEnvelope.Data.Reaction reaction) {