mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Add rudimentary message receiving via dbus
This commit is contained in:
parent
af8a27e87f
commit
0b6c09f883
1 changed files with 30 additions and 2 deletions
|
@ -23,6 +23,7 @@ import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.http.util.TextUtils;
|
import org.apache.http.util.TextUtils;
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.freedesktop.dbus.DBusConnection;
|
import org.freedesktop.dbus.DBusConnection;
|
||||||
|
import org.freedesktop.dbus.DBusSigHandler;
|
||||||
import org.freedesktop.dbus.exceptions.DBusException;
|
import org.freedesktop.dbus.exceptions.DBusException;
|
||||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||||
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
||||||
|
@ -207,8 +208,35 @@ public class Main {
|
||||||
break;
|
break;
|
||||||
case "receive":
|
case "receive":
|
||||||
if (dBusConn != null) {
|
if (dBusConn != null) {
|
||||||
System.err.println("receive is not yet implementd via dbus");
|
try {
|
||||||
System.exit(1);
|
dBusConn.addSigHandler(Signal.MessageReceived.class, new DBusSigHandler<Signal.MessageReceived>() {
|
||||||
|
@Override
|
||||||
|
public void handle(Signal.MessageReceived s) {
|
||||||
|
System.out.print(String.format("Envelope from: %s\nTimestamp: %d\nBody: %s\n",
|
||||||
|
s.getSender(), s.getTimestamp(), s.getMessage()));
|
||||||
|
if (s.getGroupId().length > 0) {
|
||||||
|
System.out.println("Group info:");
|
||||||
|
System.out.println(" Id: " + Base64.encodeBytes(s.getGroupId()));
|
||||||
|
}
|
||||||
|
if (s.getAttachments().size() > 0) {
|
||||||
|
System.out.println("Attachments: ");
|
||||||
|
for (String attachment : s.getAttachments()) {
|
||||||
|
System.out.println("- Stored plaintext in: " + attachment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (DBusException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(10000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!m.isRegistered()) {
|
if (!m.isRegistered()) {
|
||||||
System.err.println("User is not registered.");
|
System.err.println("User is not registered.");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue