mirror of
https://github.com/AsamK/signal-cli.git
synced 2026-08-12 03:16:22 +00:00
feat(json): expose voice-note attachment metadata (#2100)
Include isVoiceNote in receive JSON and JSON-RPC attachment payloads. Add regression coverage for true and false serialization.
This commit is contained in:
parent
13819c8f09
commit
0f88410465
@ -13,7 +13,8 @@ record JsonAttachment(
|
||||
Integer width,
|
||||
Integer height,
|
||||
String caption,
|
||||
Long uploadTimestamp
|
||||
Long uploadTimestamp,
|
||||
boolean isVoiceNote
|
||||
) {
|
||||
|
||||
static JsonAttachment from(MessageEnvelope.Data.Attachment attachment) {
|
||||
@ -32,6 +33,7 @@ record JsonAttachment(
|
||||
width,
|
||||
height,
|
||||
caption,
|
||||
uploadTimestamp);
|
||||
uploadTimestamp,
|
||||
attachment.isVoiceNote());
|
||||
}
|
||||
}
|
||||
|
||||
47
src/test/java/org/asamk/signal/json/JsonAttachmentTest.java
Normal file
47
src/test/java/org/asamk/signal/json/JsonAttachmentTest.java
Normal file
@ -0,0 +1,47 @@
|
||||
package org.asamk.signal.json;
|
||||
|
||||
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class JsonAttachmentTest {
|
||||
|
||||
@Test
|
||||
void serializesVoiceNoteFlag() {
|
||||
assertVoiceNoteFlag(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void serializesNonVoiceNoteFlag() {
|
||||
assertVoiceNoteFlag(false);
|
||||
}
|
||||
|
||||
private static void assertVoiceNoteFlag(final boolean isVoiceNote) {
|
||||
final var attachment = new MessageEnvelope.Data.Attachment(Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
"audio/aac",
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
isVoiceNote,
|
||||
false,
|
||||
false);
|
||||
|
||||
final var jsonAttachment = JsonAttachment.from(attachment);
|
||||
final var json = Util.createJsonObjectMapper().valueToTree(jsonAttachment);
|
||||
|
||||
assertEquals(isVoiceNote, jsonAttachment.isVoiceNote());
|
||||
assertTrue(json.has("isVoiceNote"));
|
||||
assertEquals(isVoiceNote, json.get("isVoiceNote").booleanValue());
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user