Clean up base package

This commit is contained in:
AsamK 2021-11-14 15:00:06 +01:00
parent 382d8d22d0
commit fc8b6d0fcb
60 changed files with 102 additions and 100 deletions

View file

@ -0,0 +1,37 @@
package org.asamk.signal.json;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.MessageEnvelope;
import org.asamk.signal.output.JsonWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
public class JsonReceiveMessageHandler implements Manager.ReceiveMessageHandler {
private final static Logger logger = LoggerFactory.getLogger(JsonReceiveMessageHandler.class);
private final Manager m;
private final JsonWriter jsonWriter;
public JsonReceiveMessageHandler(Manager m, JsonWriter jsonWriter) {
this.m = m;
this.jsonWriter = jsonWriter;
}
@Override
public void handleMessage(MessageEnvelope envelope, Throwable exception) {
final var object = new HashMap<String, Object>();
object.put("account", m.getSelfNumber());
if (exception != null) {
object.put("error", JsonError.from(exception));
}
if (envelope != null) {
object.put("envelope", JsonMessageEnvelope.from(envelope, exception, m));
}
jsonWriter.write(object);
}
}