Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add group name and timestamps on json message #1611

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/org/asamk/signal/json/JsonDataMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonInclude;

import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.MessageEnvelope;

import java.util.List;
Expand All @@ -25,10 +26,10 @@ record JsonDataMessage(
@JsonInclude(JsonInclude.Include.NON_NULL) JsonStoryContext storyContext
) {

static JsonDataMessage from(MessageEnvelope.Data dataMessage) {
static JsonDataMessage from(MessageEnvelope.Data dataMessage, Manager m) {
final var timestamp = dataMessage.timestamp();
final var groupInfo = dataMessage.groupContext().isPresent() ? JsonGroupInfo.from(dataMessage.groupContext()
.get()) : null;
.get(), m) : null;
final var storyContext = dataMessage.storyContext().isPresent()
? JsonStoryContext.from(dataMessage.storyContext().get())
: null;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/asamk/signal/json/JsonEditMessage.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.asamk.signal.json;

import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.MessageEnvelope;

record JsonEditMessage(long targetSentTimestamp, JsonDataMessage dataMessage) {

static JsonEditMessage from(MessageEnvelope.Edit editMessage) {
return new JsonEditMessage(editMessage.targetSentTimestamp(), JsonDataMessage.from(editMessage.dataMessage()));
static JsonEditMessage from(MessageEnvelope.Edit editMessage, Manager m) {
return new JsonEditMessage(editMessage.targetSentTimestamp(), JsonDataMessage.from(editMessage.dataMessage(), m));
}
}
7 changes: 5 additions & 2 deletions src/main/java/org/asamk/signal/json/JsonGroupInfo.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.asamk.signal.json;

import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.MessageEnvelope;

record JsonGroupInfo(String groupId, String type) {
record JsonGroupInfo(String groupId, String groupName, int revision, String type) {

static JsonGroupInfo from(MessageEnvelope.Data.GroupContext groupContext) {
static JsonGroupInfo from(MessageEnvelope.Data.GroupContext groupContext, Manager m) {
return new JsonGroupInfo(groupContext.groupId().toBase64(),
m.getGroup(groupContext.groupId()).title(),
groupContext.revision(),
groupContext.isGroupUpdate() ? "UPDATE" : "DELIVER");
}
}
18 changes: 15 additions & 3 deletions src/main/java/org/asamk/signal/json/JsonMessageEnvelope.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public record JsonMessageEnvelope(
String sourceName,
Integer sourceDevice,
long timestamp,
long serverReceivedTimestamp,
long serverDeliveredTimestamp,
@JsonInclude(JsonInclude.Include.NON_NULL) JsonDataMessage dataMessage,
@JsonInclude(JsonInclude.Include.NON_NULL) JsonEditMessage editMessage,
@JsonInclude(JsonInclude.Include.NON_NULL) JsonStoryMessage storyMessage,
Expand Down Expand Up @@ -58,13 +60,21 @@ public static JsonMessageEnvelope from(
sourceName = null;
}
final var timestamp = envelope.timestamp();
final var serverReceivedTimestamp = envelope.serverReceivedTimestamp();
final var serverDeliveredTimestamp = envelope.serverDeliveredTimestamp();
final var receiptMessage = envelope.receipt().map(JsonReceiptMessage::from).orElse(null);
final var typingMessage = envelope.typing().map(JsonTypingMessage::from).orElse(null);

final var dataMessage = envelope.data().map(JsonDataMessage::from).orElse(null);
final var editMessage = envelope.edit().map(JsonEditMessage::from).orElse(null);
final var dataMessage = envelope.data()
.map(data -> JsonDataMessage.from(data, m))
.orElse(null);
final var editMessage = envelope.edit()
.map(data -> JsonEditMessage.from(data, m))
.orElse(null);
final var storyMessage = envelope.story().map(JsonStoryMessage::from).orElse(null);
final var syncMessage = envelope.sync().map(JsonSyncMessage::from).orElse(null);
final var syncMessage = envelope.sync()
.map(data -> JsonSyncMessage.from(data, m))
.orElse(null);
final var callMessage = envelope.call().map(JsonCallMessage::from).orElse(null);

return new JsonMessageEnvelope(source,
Expand All @@ -73,6 +83,8 @@ public static JsonMessageEnvelope from(
sourceName,
sourceDevice,
timestamp,
serverReceivedTimestamp,
serverDeliveredTimestamp,
dataMessage,
editMessage,
storyMessage,
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/asamk/signal/json/JsonSyncDataMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonUnwrapped;

import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.MessageEnvelope;
import org.asamk.signal.manager.api.RecipientAddress;

Expand All @@ -16,13 +17,17 @@ record JsonSyncDataMessage(
@JsonUnwrapped JsonDataMessage dataMessage
) {

static JsonSyncDataMessage from(MessageEnvelope.Sync.Sent transcriptMessage) {
static JsonSyncDataMessage from(MessageEnvelope.Sync.Sent transcriptMessage, Manager m) {
return new JsonSyncDataMessage(transcriptMessage.destination()
.map(RecipientAddress::getLegacyIdentifier)
.orElse(null),
transcriptMessage.destination().flatMap(RecipientAddress::number).orElse(null),
transcriptMessage.destination().flatMap(address -> address.uuid().map(UUID::toString)).orElse(null),
transcriptMessage.editMessage().map(JsonEditMessage::from).orElse(null),
transcriptMessage.message().map(JsonDataMessage::from).orElse(null));
transcriptMessage.editMessage()
.map(data -> JsonEditMessage.from(data, m))
.orElse(null),
transcriptMessage.message()
.map(data -> JsonDataMessage.from(data, m))
.orElse(null));
}
}
5 changes: 3 additions & 2 deletions src/main/java/org/asamk/signal/json/JsonSyncMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonInclude;

import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.GroupId;
import org.asamk.signal.manager.api.MessageEnvelope;
import org.asamk.signal.manager.api.RecipientAddress;
Expand All @@ -23,9 +24,9 @@ record JsonSyncMessage(
@JsonInclude(JsonInclude.Include.NON_NULL) JsonSyncMessageType type
) {

static JsonSyncMessage from(MessageEnvelope.Sync syncMessage) {
static JsonSyncMessage from(MessageEnvelope.Sync syncMessage, Manager m) {
final var sentMessage = syncMessage.sent().isPresent() && syncMessage.sent().get().story().isEmpty()
? JsonSyncDataMessage.from(syncMessage.sent().get())
? JsonSyncDataMessage.from(syncMessage.sent().get(), m)
: null;
final var sentStoryMessage = syncMessage.sent().isPresent() && syncMessage.sent().get().story().isPresent()
? JsonSyncStoryMessage.from(syncMessage.sent().get())
Expand Down
Loading