mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 19:10:38 +00:00
Clean up base package
This commit is contained in:
parent
382d8d22d0
commit
fc8b6d0fcb
60 changed files with 102 additions and 100 deletions
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue