mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Extract static methods from Main
This commit is contained in:
parent
184354ffb7
commit
860ec6f5dc
8 changed files with 520 additions and 440 deletions
|
@ -0,0 +1,71 @@
|
|||
package org.asamk.signal;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.freedesktop.dbus.DBusConnection;
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
import org.whispersystems.signalservice.api.messages.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
||||
|
||||
private final DBusConnection conn;
|
||||
|
||||
private final String objectPath;
|
||||
|
||||
JsonDbusReceiveMessageHandler(Manager m, DBusConnection conn, final String objectPath) {
|
||||
super(m);
|
||||
this.conn = conn;
|
||||
this.objectPath = objectPath;
|
||||
}
|
||||
|
||||
static void sendReceivedMessageToDbus(SignalServiceEnvelope envelope, SignalServiceContent content, DBusConnection conn, final String objectPath, Manager m) {
|
||||
if (envelope.isReceipt()) {
|
||||
try {
|
||||
conn.sendSignal(new Signal.ReceiptReceived(
|
||||
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(
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
|
||||
super.handleMessage(envelope, content, exception);
|
||||
|
||||
sendReceivedMessageToDbus(envelope, content, conn, objectPath, m);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue