Refactor receive api

This commit is contained in:
AsamK 2021-11-03 20:43:39 +01:00
parent b615a4b04d
commit 9075cc1a30
36 changed files with 1510 additions and 970 deletions

View file

@ -1,22 +1,14 @@
package org.asamk.signal.json;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.asamk.signal.manager.api.MessageEnvelope;
record JsonAttachment(String contentType, String filename, String id, Long size) {
static JsonAttachment from(SignalServiceAttachment attachment) {
if (attachment.isPointer()) {
final var pointer = attachment.asPointer();
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();
final var filename = stream.getFileName().orNull();
final var size = stream.getLength();
return new JsonAttachment(attachment.getContentType(), filename, null, size);
}
static JsonAttachment from(MessageEnvelope.Data.Attachment attachment) {
final var id = attachment.id().orElse(null);
final var filename = attachment.fileName().orElse(null);
final var size = attachment.size().orElse(null);
return new JsonAttachment(attachment.contentType(), filename, id, size);
}
static JsonAttachment from(String filename) {