mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Refactor receive api
This commit is contained in:
parent
b615a4b04d
commit
9075cc1a30
36 changed files with 1510 additions and 970 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue