mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Implement receive handling for story messages
This commit is contained in:
parent
81e36d4f9b
commit
a593051512
12 changed files with 443 additions and 47 deletions
|
@ -68,6 +68,10 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
var message = envelope.data().get();
|
||||
printDataMessage(writer, message);
|
||||
}
|
||||
if (envelope.story().isPresent()) {
|
||||
var message = envelope.story().get();
|
||||
printStoryMessage(writer.indentedWriter(), message);
|
||||
}
|
||||
if (envelope.sync().isPresent()) {
|
||||
writer.println("Received a sync message");
|
||||
var syncMessage = envelope.sync().get();
|
||||
|
@ -107,6 +111,11 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
final var groupContext = message.groupContext().get();
|
||||
printGroupContext(writer.indentedWriter(), groupContext);
|
||||
}
|
||||
if (message.storyContext().isPresent()) {
|
||||
writer.println("Story reply:");
|
||||
final var storyContext = message.storyContext().get();
|
||||
printStoryContext(writer.indentedWriter(), storyContext);
|
||||
}
|
||||
if (message.groupCallUpdate().isPresent()) {
|
||||
writer.println("Group call update:");
|
||||
final var groupCallUpdate = message.groupCallUpdate().get();
|
||||
|
@ -176,6 +185,28 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private void printStoryMessage(
|
||||
PlainTextWriter writer, MessageEnvelope.Story message
|
||||
) {
|
||||
writer.println("Story: with replies: {}", message.allowsReplies());
|
||||
if (message.groupId().isPresent()) {
|
||||
writer.println("Group info:");
|
||||
printGroupInfo(writer.indentedWriter(), message.groupId().get());
|
||||
}
|
||||
if (message.textAttachment().isPresent()) {
|
||||
writer.println("Body: {}", message.textAttachment().get().text().orElse(""));
|
||||
|
||||
if (message.textAttachment().get().preview().isPresent()) {
|
||||
writer.println("Preview:");
|
||||
printPreview(writer.indentedWriter(), message.textAttachment().get().preview().get());
|
||||
}
|
||||
}
|
||||
if (message.fileAttachment().isPresent()) {
|
||||
writer.println("Attachments:");
|
||||
printAttachment(writer.indentedWriter(), message.fileAttachment().get());
|
||||
}
|
||||
}
|
||||
|
||||
private void printTypingMessage(
|
||||
final PlainTextWriter writer, final MessageEnvelope.Typing typingMessage
|
||||
) {
|
||||
|
@ -305,6 +336,10 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
var message = sentTranscriptMessage.message().get();
|
||||
printDataMessage(writer.indentedWriter(), message);
|
||||
}
|
||||
if (sentTranscriptMessage.story().isPresent()) {
|
||||
var message = sentTranscriptMessage.story().get();
|
||||
printStoryMessage(writer.indentedWriter(), message);
|
||||
}
|
||||
}
|
||||
if (syncMessage.blocked().isPresent()) {
|
||||
writer.println("Received sync message with block list");
|
||||
|
@ -495,6 +530,13 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
writer.println("Type: {}", groupContext.isGroupUpdate() ? "UPDATE" : "DELIVER");
|
||||
}
|
||||
|
||||
private void printStoryContext(
|
||||
final PlainTextWriter writer, final MessageEnvelope.Data.StoryContext storyContext
|
||||
) {
|
||||
writer.println("Sender: {}", formatContact(storyContext.author()));
|
||||
writer.println("Sent timestamp: {}", storyContext.sentTimestamp());
|
||||
}
|
||||
|
||||
private void printGroupInfo(final PlainTextWriter writer, final GroupId groupId) {
|
||||
writer.println("Id: {}", groupId.toBase64());
|
||||
|
||||
|
|
|
@ -751,6 +751,7 @@ public class DbusManagerImpl implements Manager {
|
|||
messageReceived.getGroupId()), false, 0))
|
||||
: Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.of(messageReceived.getMessage()),
|
||||
0,
|
||||
false,
|
||||
|
@ -768,6 +769,7 @@ public class DbusManagerImpl implements Manager {
|
|||
List.of(),
|
||||
List.of())),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty());
|
||||
notifyMessageHandlers(envelope);
|
||||
};
|
||||
|
@ -793,6 +795,7 @@ public class DbusManagerImpl implements Manager {
|
|||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty());
|
||||
notifyMessageHandlers(envelope);
|
||||
};
|
||||
|
@ -822,6 +825,7 @@ public class DbusManagerImpl implements Manager {
|
|||
syncReceived.getGroupId()), false, 0))
|
||||
: Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.of(syncReceived.getMessage()),
|
||||
0,
|
||||
false,
|
||||
|
@ -837,7 +841,8 @@ public class DbusManagerImpl implements Manager {
|
|||
Optional.empty(),
|
||||
List.of(),
|
||||
List.of(),
|
||||
List.of())))),
|
||||
List.of())),
|
||||
Optional.empty())),
|
||||
Optional.empty(),
|
||||
List.of(),
|
||||
List.of(),
|
||||
|
@ -845,6 +850,7 @@ public class DbusManagerImpl implements Manager {
|
|||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty())),
|
||||
Optional.empty(),
|
||||
Optional.empty());
|
||||
notifyMessageHandlers(envelope);
|
||||
};
|
||||
|
|
|
@ -20,13 +20,17 @@ record JsonDataMessage(
|
|||
@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
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonGroupInfo groupInfo,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonStoryContext storyContext
|
||||
) {
|
||||
|
||||
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 storyContext = dataMessage.storyContext().isPresent()
|
||||
? JsonStoryContext.from(dataMessage.storyContext().get())
|
||||
: null;
|
||||
final var message = dataMessage.body().orElse(null);
|
||||
final var expiresInSeconds = dataMessage.expiresInSeconds();
|
||||
final var viewOnce = dataMessage.isViewOnce();
|
||||
|
@ -67,6 +71,7 @@ record JsonDataMessage(
|
|||
sticker,
|
||||
remoteDelete,
|
||||
contacts,
|
||||
groupInfo);
|
||||
groupInfo,
|
||||
storyContext);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ public record JsonMessageEnvelope(
|
|||
Integer sourceDevice,
|
||||
long timestamp,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonDataMessage dataMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonStoryMessage storyMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonSyncMessage syncMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonCallMessage callMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonReceiptMessage receiptMessage,
|
||||
|
@ -60,6 +61,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 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);
|
||||
|
||||
|
@ -70,6 +72,7 @@ public record JsonMessageEnvelope(
|
|||
sourceDevice,
|
||||
timestamp,
|
||||
dataMessage,
|
||||
storyMessage,
|
||||
syncMessage,
|
||||
callMessage,
|
||||
receiptMessage,
|
||||
|
|
16
src/main/java/org/asamk/signal/json/JsonStoryContext.java
Normal file
16
src/main/java/org/asamk/signal/json/JsonStoryContext.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
record JsonStoryContext(
|
||||
String authorNumber, String authorUuid, long sentTimestamp
|
||||
) {
|
||||
|
||||
static JsonStoryContext from(MessageEnvelope.Data.StoryContext storyContext) {
|
||||
return new JsonStoryContext(storyContext.author().number().orElse(null),
|
||||
storyContext.author().uuid().map(UUID::toString).orElse(null),
|
||||
storyContext.sentTimestamp());
|
||||
}
|
||||
}
|
52
src/main/java/org/asamk/signal/json/JsonStoryMessage.java
Normal file
52
src/main/java/org/asamk/signal/json/JsonStoryMessage.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import org.asamk.signal.manager.api.Color;
|
||||
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
|
||||
record JsonStoryMessage(
|
||||
boolean allowsReplies,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) String groupId,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonAttachment fileAttachment,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) TextAttachment textAttachment
|
||||
) {
|
||||
|
||||
static JsonStoryMessage from(MessageEnvelope.Story storyMessage) {
|
||||
return new JsonStoryMessage(storyMessage.allowsReplies(),
|
||||
storyMessage.groupId().map(GroupId::toBase64).orElse(null),
|
||||
storyMessage.fileAttachment().map(JsonAttachment::from).orElse(null),
|
||||
storyMessage.textAttachment().map(TextAttachment::from).orElse(null));
|
||||
}
|
||||
|
||||
public record TextAttachment(
|
||||
String text,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) String style,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) String textForegroundColor,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) String textBackgroundColor,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonPreview preview,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) Gradient backgroundGradient,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) String backgroundColor
|
||||
) {
|
||||
|
||||
static TextAttachment from(MessageEnvelope.Story.TextAttachment textAttachment) {
|
||||
return new TextAttachment(textAttachment.text().orElse(null),
|
||||
textAttachment.style().map(MessageEnvelope.Story.TextAttachment.Style::name).orElse(null),
|
||||
textAttachment.textForegroundColor().map(Color::toHexColor).orElse(null),
|
||||
textAttachment.textBackgroundColor().map(Color::toHexColor).orElse(null),
|
||||
textAttachment.preview().map(JsonPreview::from).orElse(null),
|
||||
textAttachment.backgroundGradient().map(Gradient::from).orElse(null),
|
||||
textAttachment.backgroundColor().map(Color::toHexColor).orElse(null));
|
||||
}
|
||||
|
||||
public record Gradient(String startColor, String endColor, Integer angle) {
|
||||
|
||||
static Gradient from(MessageEnvelope.Story.TextAttachment.Gradient gradient) {
|
||||
return new Gradient(gradient.startColor().map(Color::toHexColor).orElse(null),
|
||||
gradient.endColor().map(Color::toHexColor).orElse(null),
|
||||
gradient.angle().orElse(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,30 +16,20 @@ enum JsonSyncMessageType {
|
|||
|
||||
record JsonSyncMessage(
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonSyncDataMessage sentMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonSyncStoryMessage sentStoryMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<String> blockedNumbers,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<String> blockedGroupIds,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonSyncReadMessage> readMessages,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonSyncMessageType type
|
||||
) {
|
||||
|
||||
JsonSyncMessage(
|
||||
final JsonSyncDataMessage sentMessage,
|
||||
final List<String> blockedNumbers,
|
||||
final List<String> blockedGroupIds,
|
||||
final List<JsonSyncReadMessage> readMessages,
|
||||
final JsonSyncMessageType type
|
||||
) {
|
||||
this.sentMessage = sentMessage;
|
||||
this.blockedNumbers = blockedNumbers;
|
||||
this.blockedGroupIds = blockedGroupIds;
|
||||
this.readMessages = readMessages;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
static JsonSyncMessage from(MessageEnvelope.Sync syncMessage) {
|
||||
final var sentMessage = syncMessage.sent().isPresent()
|
||||
final var sentMessage = syncMessage.sent().isPresent() && syncMessage.sent().get().story().isEmpty()
|
||||
? JsonSyncDataMessage.from(syncMessage.sent().get())
|
||||
: null;
|
||||
final var sentStoryMessage = syncMessage.sent().isPresent() && syncMessage.sent().get().story().isPresent()
|
||||
? JsonSyncStoryMessage.from(syncMessage.sent().get())
|
||||
: null;
|
||||
final List<String> blockedNumbers;
|
||||
final List<String> blockedGroupIds;
|
||||
if (syncMessage.blocked().isPresent()) {
|
||||
|
@ -68,6 +58,6 @@ record JsonSyncMessage(
|
|||
} else {
|
||||
type = null;
|
||||
}
|
||||
return new JsonSyncMessage(sentMessage, blockedNumbers, blockedGroupIds, readMessages, type);
|
||||
return new JsonSyncMessage(sentMessage, sentStoryMessage, blockedNumbers, blockedGroupIds, readMessages, type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
||||
|
||||
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
record JsonSyncStoryMessage(
|
||||
String destinationNumber, String destinationUuid, @JsonUnwrapped JsonStoryMessage dataMessage
|
||||
) {
|
||||
|
||||
static JsonSyncStoryMessage from(MessageEnvelope.Sync.Sent transcriptMessage) {
|
||||
if (transcriptMessage.destination().isPresent()) {
|
||||
final var address = transcriptMessage.destination().get();
|
||||
return new JsonSyncStoryMessage(address.number().orElse(null),
|
||||
address.uuid().map(UUID::toString).orElse(null),
|
||||
transcriptMessage.story().map(JsonStoryMessage::from).orElse(null));
|
||||
|
||||
} else {
|
||||
return new JsonSyncStoryMessage(null,
|
||||
null,
|
||||
transcriptMessage.story().map(JsonStoryMessage::from).orElse(null));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue