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
|
@ -3,8 +3,7 @@ package org.asamk.signal.json;
|
|||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -24,66 +23,32 @@ record JsonDataMessage(
|
|||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonGroupInfo groupInfo
|
||||
) {
|
||||
|
||||
static JsonDataMessage from(SignalServiceDataMessage dataMessage, Manager m) {
|
||||
final var timestamp = dataMessage.getTimestamp();
|
||||
final JsonGroupInfo groupInfo;
|
||||
if (dataMessage.getGroupContext().isPresent()) {
|
||||
final var groupContext = dataMessage.getGroupContext().get();
|
||||
if (groupContext.getGroupV1().isPresent()) {
|
||||
var group = groupContext.getGroupV1().get();
|
||||
groupInfo = JsonGroupInfo.from(group);
|
||||
} else if (groupContext.getGroupV2().isPresent()) {
|
||||
var group = groupContext.getGroupV2().get();
|
||||
groupInfo = JsonGroupInfo.from(group);
|
||||
} else {
|
||||
groupInfo = null;
|
||||
}
|
||||
} else {
|
||||
groupInfo = null;
|
||||
}
|
||||
final var message = dataMessage.getBody().orNull();
|
||||
final var expiresInSeconds = dataMessage.getExpiresInSeconds();
|
||||
static JsonDataMessage from(MessageEnvelope.Data dataMessage) {
|
||||
final var timestamp = dataMessage.timestamp();
|
||||
final var groupInfo = dataMessage.groupContext().isPresent() ? JsonGroupInfo.from(dataMessage.groupContext()
|
||||
.get()) : null;
|
||||
final var message = dataMessage.body().orElse(null);
|
||||
final var expiresInSeconds = dataMessage.expiresInSeconds();
|
||||
final var viewOnce = dataMessage.isViewOnce();
|
||||
final var reaction = dataMessage.getReaction().isPresent() ? JsonReaction.from(dataMessage.getReaction().get(),
|
||||
m) : null;
|
||||
final var quote = dataMessage.getQuote().isPresent() ? JsonQuote.from(dataMessage.getQuote().get(), m) : null;
|
||||
final List<JsonMention> mentions;
|
||||
if (dataMessage.getMentions().isPresent()) {
|
||||
mentions = dataMessage.getMentions()
|
||||
.get()
|
||||
.stream()
|
||||
.map(mention -> JsonMention.from(mention, m))
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
mentions = List.of();
|
||||
}
|
||||
final var remoteDelete = dataMessage.getRemoteDelete().isPresent()
|
||||
? JsonRemoteDelete.from(dataMessage.getRemoteDelete().get())
|
||||
: null;
|
||||
final List<JsonAttachment> attachments;
|
||||
if (dataMessage.getAttachments().isPresent()) {
|
||||
attachments = dataMessage.getAttachments()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonAttachment::from)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
attachments = List.of();
|
||||
}
|
||||
final var sticker = dataMessage.getSticker().isPresent()
|
||||
? JsonSticker.from(dataMessage.getSticker().get())
|
||||
final var reaction = dataMessage.reaction().map(JsonReaction::from).orElse(null);
|
||||
final var quote = dataMessage.quote().isPresent() ? JsonQuote.from(dataMessage.quote().get()) : null;
|
||||
final var mentions = dataMessage.mentions().size() > 0 ? dataMessage.mentions()
|
||||
.stream()
|
||||
.map(JsonMention::from)
|
||||
.collect(Collectors.toList()) : null;
|
||||
final var remoteDelete = dataMessage.remoteDeleteId().isPresent()
|
||||
? new JsonRemoteDelete(dataMessage.remoteDeleteId().get())
|
||||
: null;
|
||||
final var attachments = dataMessage.attachments().size() > 0 ? dataMessage.attachments()
|
||||
.stream()
|
||||
.map(JsonAttachment::from)
|
||||
.collect(Collectors.toList()) : null;
|
||||
final var sticker = dataMessage.sticker().isPresent() ? JsonSticker.from(dataMessage.sticker().get()) : null;
|
||||
|
||||
final List<JsonSharedContact> contacts;
|
||||
if (dataMessage.getSharedContacts().isPresent()) {
|
||||
contacts = dataMessage.getSharedContacts()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonSharedContact::from)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
contacts = List.of();
|
||||
}
|
||||
final var contacts = dataMessage.sharedContacts().size() > 0 ? dataMessage.sharedContacts()
|
||||
.stream()
|
||||
.map(JsonSharedContact::from)
|
||||
.collect(Collectors.toList()) : null;
|
||||
return new JsonDataMessage(timestamp,
|
||||
message,
|
||||
expiresInSeconds,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue