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:
Bazyli Brzóska 2026-08-10 01:38:27 -07:00 committed by GitHub
parent 13819c8f09
commit 0f88410465
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 51 additions and 2 deletions

View File

@ -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());
}
}

View 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());
}
}