Implement editing of previous messages

This commit is contained in:
AsamK 2023-05-11 19:10:29 +02:00
parent 72390e595d
commit 8a31b7f2c1
13 changed files with 179 additions and 42 deletions

View file

@ -0,0 +1,10 @@
package org.asamk.signal.json;
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()));
}
}

View file

@ -18,6 +18,7 @@ public record JsonMessageEnvelope(
Integer sourceDevice,
long timestamp,
@JsonInclude(JsonInclude.Include.NON_NULL) JsonDataMessage dataMessage,
@JsonInclude(JsonInclude.Include.NON_NULL) JsonEditMessage editMessage,
@JsonInclude(JsonInclude.Include.NON_NULL) JsonStoryMessage storyMessage,
@JsonInclude(JsonInclude.Include.NON_NULL) JsonSyncMessage syncMessage,
@JsonInclude(JsonInclude.Include.NON_NULL) JsonCallMessage callMessage,
@ -61,6 +62,7 @@ public record JsonMessageEnvelope(
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 storyMessage = envelope.story().map(JsonStoryMessage::from).orElse(null);
final var syncMessage = envelope.sync().map(JsonSyncMessage::from).orElse(null);
final var callMessage = envelope.call().map(JsonCallMessage::from).orElse(null);
@ -72,6 +74,7 @@ public record JsonMessageEnvelope(
sourceDevice,
timestamp,
dataMessage,
editMessage,
storyMessage,
syncMessage,
callMessage,

View file

@ -1,8 +1,10 @@
package org.asamk.signal.json;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import org.asamk.signal.manager.api.MessageEnvelope;
import org.asamk.signal.manager.api.RecipientAddress;
import java.util.UUID;
@ -10,22 +12,17 @@ record JsonSyncDataMessage(
@Deprecated String destination,
String destinationNumber,
String destinationUuid,
@JsonInclude(JsonInclude.Include.NON_NULL) JsonEditMessage editMessage,
@JsonUnwrapped JsonDataMessage dataMessage
) {
static JsonSyncDataMessage from(MessageEnvelope.Sync.Sent transcriptMessage) {
if (transcriptMessage.destination().isPresent()) {
final var address = transcriptMessage.destination().get();
return new JsonSyncDataMessage(address.getLegacyIdentifier(),
address.number().orElse(null),
address.uuid().map(UUID::toString).orElse(null),
transcriptMessage.message().map(JsonDataMessage::from).orElse(null));
} else {
return new JsonSyncDataMessage(null,
null,
null,
transcriptMessage.message().map(JsonDataMessage::from).orElse(null));
}
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));
}
}