mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Use record classes
This commit is contained in:
parent
ce70a623c2
commit
ce7aa580b6
66 changed files with 754 additions and 1877 deletions
|
@ -1,43 +1,25 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||
|
||||
class JsonAttachment {
|
||||
|
||||
@JsonProperty
|
||||
final String contentType;
|
||||
|
||||
@JsonProperty
|
||||
final String filename;
|
||||
|
||||
@JsonProperty
|
||||
final String id;
|
||||
|
||||
@JsonProperty
|
||||
final Long size;
|
||||
|
||||
JsonAttachment(SignalServiceAttachment attachment) {
|
||||
this.contentType = attachment.getContentType();
|
||||
record JsonAttachment(String contentType, String filename, String id, Long size) {
|
||||
|
||||
static JsonAttachment from(SignalServiceAttachment attachment) {
|
||||
if (attachment.isPointer()) {
|
||||
final var pointer = attachment.asPointer();
|
||||
this.id = pointer.getRemoteId().toString();
|
||||
this.filename = pointer.getFileName().orNull();
|
||||
this.size = pointer.getSize().transform(Integer::longValue).orNull();
|
||||
final var id = pointer.getRemoteId().toString();
|
||||
final var filename = pointer.getFileName().orNull();
|
||||
final var size = pointer.getSize().transform(Integer::longValue).orNull();
|
||||
return new JsonAttachment(attachment.getContentType(), filename, id, size);
|
||||
} else {
|
||||
final var stream = attachment.asStream();
|
||||
this.id = null;
|
||||
this.filename = stream.getFileName().orNull();
|
||||
this.size = stream.getLength();
|
||||
final var filename = stream.getFileName().orNull();
|
||||
final var size = stream.getLength();
|
||||
return new JsonAttachment(attachment.getContentType(), filename, null, size);
|
||||
}
|
||||
}
|
||||
|
||||
JsonAttachment(String filename) {
|
||||
this.filename = filename;
|
||||
this.contentType = null;
|
||||
this.id = null;
|
||||
this.size = null;
|
||||
static JsonAttachment from(String filename) {
|
||||
return new JsonAttachment(filename, null, null, null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue