+ public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
+ super.handleMessage(envelope, content, exception);
+
+ if (envelope.isReceipt()) {
+ try {
+ conn.sendSignal(new Signal.ReceiptReceived(
+ SIGNAL_OBJECTPATH,
+ envelope.getTimestamp(),
+ envelope.getSource()
+ ));
+ } catch (DBusException e) {
+ e.printStackTrace();
+ }
+ } else if (content != null && content.getDataMessage().isPresent()) {
+ SignalServiceDataMessage message = content.getDataMessage().get();
+
+ if (!message.isEndSession() &&
+ !(message.getGroupInfo().isPresent() &&
+ message.getGroupInfo().get().getType() != SignalServiceGroup.Type.DELIVER)) {
+ List<String> attachments = new ArrayList<>();
+ if (message.getAttachments().isPresent()) {
+ for (SignalServiceAttachment attachment : message.getAttachments().get()) {
+ if (attachment.isPointer()) {
+ attachments.add(m.getAttachmentFile(attachment.asPointer().getId()).getAbsolutePath());
+ }
+ }
+ }
+
+ try {
+ conn.sendSignal(new Signal.MessageReceived(
+ SIGNAL_OBJECTPATH,
+ message.getTimestamp(),
+ envelope.getSource(),
+ message.getGroupInfo().isPresent() ? message.getGroupInfo().get().getGroupId() : new byte[0],
+ message.getBody().isPresent() ? message.getBody().get() : "",
+ attachments));
+ } catch (DBusException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ private static class JsonReceiveMessageHandler implements Manager.ReceiveMessageHandler {
+ final Manager m;
+ final ObjectMapper jsonProcessor;
+
+ public JsonReceiveMessageHandler(Manager m) {
+ this.m = m;
+ this.jsonProcessor = new ObjectMapper();
+ jsonProcessor.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); // disable autodetect
+ jsonProcessor.enable(SerializationFeature.WRITE_NULL_MAP_VALUES);
+ jsonProcessor.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ jsonProcessor.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
+ }
+
+ @Override
+ public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
+ ObjectNode result = jsonProcessor.createObjectNode();
+ if (exception != null) {
+ result.putPOJO("error", new JsonError(exception));
+ }
+ if (envelope != null) {
+ result.putPOJO("envelope", new JsonMessageEnvelope(envelope, content));
+ }
+ try {
+ jsonProcessor.writeValue(System.out, result);
+ System.out.println();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
+ final DBusConnection conn;
+
+ public JsonDbusReceiveMessageHandler(Manager m, DBusConnection conn) {
+ super(m);
+ this.conn = conn;
+ }
+
+ @Override
+ public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
+ super.handleMessage(envelope, content, exception);