mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Make fields in json classes final and omit unnecessary nulls when serializing
Fix sender in sync read messages
This commit is contained in:
parent
dd4225dcb1
commit
46a4c2c0d0
16 changed files with 374 additions and 150 deletions
|
@ -1,31 +1,45 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
|
||||
|
||||
class JsonAttachment {
|
||||
|
||||
String contentType;
|
||||
String filename;
|
||||
String id;
|
||||
int size;
|
||||
@JsonProperty
|
||||
final String contentType;
|
||||
|
||||
@JsonProperty
|
||||
final String filename;
|
||||
|
||||
@JsonProperty
|
||||
final String id;
|
||||
|
||||
@JsonProperty
|
||||
final Long size;
|
||||
|
||||
JsonAttachment(SignalServiceAttachment attachment) {
|
||||
this.contentType = attachment.getContentType();
|
||||
|
||||
final SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
||||
if (attachment.isPointer()) {
|
||||
this.id = String.valueOf(pointer.getRemoteId());
|
||||
if (pointer.getFileName().isPresent()) {
|
||||
this.filename = pointer.getFileName().get();
|
||||
}
|
||||
if (pointer.getSize().isPresent()) {
|
||||
this.size = pointer.getSize().get();
|
||||
}
|
||||
final SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
||||
this.id = pointer.getRemoteId().toString();
|
||||
this.filename = pointer.getFileName().orNull();
|
||||
this.size = pointer.getSize().transform(Integer::longValue).orNull();
|
||||
} else {
|
||||
final SignalServiceAttachmentStream stream = attachment.asStream();
|
||||
this.id = null;
|
||||
this.filename = stream.getFileName().orNull();
|
||||
this.size = stream.getLength();
|
||||
}
|
||||
}
|
||||
|
||||
JsonAttachment(String filename) {
|
||||
this.filename = filename;
|
||||
this.contentType = null;
|
||||
this.id = null;
|
||||
this.size = null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue