mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Output json when receiving messages from dbus and --json parameter is given
Fixes #138
This commit is contained in:
parent
e04c45766d
commit
ae41d0c502
15 changed files with 176 additions and 50 deletions
50
src/main/java/org/asamk/signal/json/JsonSyncMessage.java
Normal file
50
src/main/java/org/asamk/signal/json/JsonSyncMessage.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
enum JsonSyncMessageType {
|
||||
CONTACTS_SYNC,
|
||||
GROUPS_SYNC,
|
||||
REQUEST_SYNC
|
||||
}
|
||||
|
||||
class JsonSyncMessage {
|
||||
|
||||
JsonSyncDataMessage sentMessage;
|
||||
List<String> blockedNumbers;
|
||||
List<ReadMessage> readMessages;
|
||||
JsonSyncMessageType type;
|
||||
|
||||
JsonSyncMessage(SignalServiceSyncMessage syncMessage) {
|
||||
if (syncMessage.getSent().isPresent()) {
|
||||
this.sentMessage = new JsonSyncDataMessage(syncMessage.getSent().get());
|
||||
}
|
||||
if (syncMessage.getBlockedList().isPresent()) {
|
||||
this.blockedNumbers = new ArrayList<>(syncMessage.getBlockedList().get().getAddresses().size());
|
||||
for (SignalServiceAddress address : syncMessage.getBlockedList().get().getAddresses()) {
|
||||
this.blockedNumbers.add(address.getNumber().get());
|
||||
}
|
||||
}
|
||||
if (syncMessage.getRead().isPresent()) {
|
||||
this.readMessages = syncMessage.getRead().get();
|
||||
}
|
||||
|
||||
if (syncMessage.getContacts().isPresent()) {
|
||||
this.type = JsonSyncMessageType.CONTACTS_SYNC;
|
||||
} else if (syncMessage.getGroups().isPresent()) {
|
||||
this.type = JsonSyncMessageType.GROUPS_SYNC;
|
||||
} else if (syncMessage.getRequest().isPresent()) {
|
||||
this.type = JsonSyncMessageType.REQUEST_SYNC;
|
||||
}
|
||||
}
|
||||
|
||||
JsonSyncMessage(Signal.SyncMessageReceived messageReceived) {
|
||||
sentMessage = new JsonSyncDataMessage(messageReceived);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue