-class JsonDataMessage {
-
- long timestamp;
- String message;
- int expiresInSeconds;
- List<JsonAttachment> attachments;
- JsonGroupInfo groupInfo;
-
- JsonDataMessage(SignalServiceDataMessage dataMessage) {
- this.timestamp = dataMessage.getTimestamp();
- if (dataMessage.getGroupContext().isPresent()) {
- if (dataMessage.getGroupContext().get().getGroupV1().isPresent()) {
- SignalServiceGroup groupInfo = dataMessage.getGroupContext().get().getGroupV1().get();
- this.groupInfo = new JsonGroupInfo(groupInfo);
- } else if (dataMessage.getGroupContext().get().getGroupV2().isPresent()) {
- SignalServiceGroupV2 groupInfo = dataMessage.getGroupContext().get().getGroupV2().get();
- this.groupInfo = new JsonGroupInfo(groupInfo);
- }
- }
- if (dataMessage.getBody().isPresent()) {
- this.message = dataMessage.getBody().get();
- }
- this.expiresInSeconds = dataMessage.getExpiresInSeconds();
- if (dataMessage.getAttachments().isPresent()) {
- this.attachments = new ArrayList<>(dataMessage.getAttachments().get().size());
- for (SignalServiceAttachment attachment : dataMessage.getAttachments().get()) {
- this.attachments.add(new JsonAttachment(attachment));
- }
- } else {
- this.attachments = new ArrayList<>();
- }
+record JsonDataMessage(
+ long timestamp,
+ String message,
+ Integer expiresInSeconds,
+ @JsonInclude(JsonInclude.Include.NON_NULL) Boolean viewOnce,
+ @JsonInclude(JsonInclude.Include.NON_NULL) JsonReaction reaction,
+ @JsonInclude(JsonInclude.Include.NON_NULL) JsonQuote quote,
+ @JsonInclude(JsonInclude.Include.NON_NULL) List<JsonMention> mentions,
+ @JsonInclude(JsonInclude.Include.NON_NULL) List<JsonAttachment> attachments,
+ @JsonInclude(JsonInclude.Include.NON_NULL) JsonSticker sticker,
+ @JsonInclude(JsonInclude.Include.NON_NULL) JsonRemoteDelete remoteDelete,
+ @JsonInclude(JsonInclude.Include.NON_NULL) List<JsonSharedContact> contacts,
+ @JsonInclude(JsonInclude.Include.NON_NULL) JsonGroupInfo groupInfo
+) {
+
+ static JsonDataMessage from(MessageEnvelope.Data dataMessage) {
+ final var timestamp = dataMessage.timestamp();
+ final var groupInfo = dataMessage.groupContext().isPresent() ? JsonGroupInfo.from(dataMessage.groupContext()
+ .get()) : null;
+ final var message = dataMessage.body().orElse(null);
+ final var expiresInSeconds = dataMessage.expiresInSeconds();
+ final var viewOnce = dataMessage.isViewOnce();
+ final var reaction = dataMessage.reaction().map(JsonReaction::from).orElse(null);
+ final var quote = dataMessage.quote().isPresent() ? JsonQuote.from(dataMessage.quote().get()) : null;
+ final var mentions = dataMessage.mentions().size() > 0 ? dataMessage.mentions()
+ .stream()
+ .map(JsonMention::from)
+ .collect(Collectors.toList()) : null;
+ final var remoteDelete = dataMessage.remoteDeleteId().isPresent()
+ ? new JsonRemoteDelete(dataMessage.remoteDeleteId().get())
+ : null;
+ final var attachments = dataMessage.attachments().size() > 0 ? dataMessage.attachments()
+ .stream()
+ .map(JsonAttachment::from)
+ .collect(Collectors.toList()) : null;
+ final var sticker = dataMessage.sticker().isPresent() ? JsonSticker.from(dataMessage.sticker().get()) : null;
+
+ final var contacts = dataMessage.sharedContacts().size() > 0 ? dataMessage.sharedContacts()
+ .stream()
+ .map(JsonSharedContact::from)
+ .collect(Collectors.toList()) : null;
+ return new JsonDataMessage(timestamp,
+ message,
+ expiresInSeconds,
+ viewOnce,
+ reaction,
+ quote,
+ mentions,
+ attachments,
+ sticker,
+ remoteDelete,
+ contacts,
+ groupInfo);