X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/7443225d96fd830c8abb2afd49381f6b38ce5aec..35c72f692f13b12594ecdbe8f59f31d3b396d356:/src/main/java/org/asamk/signal/Main.java diff --git a/src/main/java/org/asamk/signal/Main.java b/src/main/java/org/asamk/signal/Main.java index 03d1c3cc..810f1deb 100644 --- a/src/main/java/org/asamk/signal/Main.java +++ b/src/main/java/org/asamk/signal/Main.java @@ -1,18 +1,18 @@ -/** - * Copyright (C) 2015 AsamK - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . +/* + Copyright (C) 2015-2018 AsamK + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ package org.asamk.signal; @@ -28,6 +28,8 @@ import net.sourceforge.argparse4j.impl.Arguments; import net.sourceforge.argparse4j.inf.*; import org.apache.http.util.TextUtils; import org.asamk.Signal; +import org.asamk.signal.manager.BaseConfig; +import org.asamk.signal.manager.Manager; import org.asamk.signal.storage.contacts.ContactInfo; import org.asamk.signal.storage.groups.GroupInfo; import org.asamk.signal.storage.protocol.JsonIdentityKeyStore; @@ -127,13 +129,11 @@ public class Main { m = new Manager(username, settingsPath); ts = m; - if (m.userExists()) { - try { - m.init(); - } catch (Exception e) { - System.err.println("Error loading state file \"" + m.getFileName() + "\": " + e.getMessage()); - return 2; - } + try { + m.init(); + } catch (Exception e) { + System.err.println("Error loading state file: " + e.getMessage()); + return 2; } } @@ -143,9 +143,6 @@ public class Main { System.err.println("register is not yet implemented via dbus"); return 1; } - if (!m.userHasKeys()) { - m.createNewIdentity(); - } try { m.register(ns.getBoolean("voice")); } catch (IOException e) { @@ -250,9 +247,6 @@ public class Main { return 1; } - // When linking, username is null and we always have to create keys - m.createNewIdentity(); - String deviceName = ns.getString("name"); if (deviceName == null) { deviceName = "cli"; @@ -734,7 +728,6 @@ public class Main { System.err.println("Aborting sending."); } - private static void handleDBusExecutionException(DBusExecutionException e) { System.err.println("Cannot connect to dbus: " + e.getMessage()); System.err.println("Aborting."); @@ -756,7 +749,7 @@ public class Main { .build() .defaultHelp(true) .description("Commandline interface for Signal.") - .version(Manager.PROJECT_NAME + " " + Manager.PROJECT_VERSION); + .version(BaseConfig.PROJECT_NAME + " " + BaseConfig.PROJECT_VERSION); parser.addArgument("-v", "--version") .help("Show package version.") @@ -947,6 +940,7 @@ public class Main { } private static class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { + final Manager m; public ReceiveMessageHandler(Manager m) { @@ -1210,6 +1204,7 @@ public class Main { } private static class DbusReceiveMessageHandler extends ReceiveMessageHandler { + final DBusConnection conn; public DbusReceiveMessageHandler(Manager m, DBusConnection conn) { @@ -1226,6 +1221,7 @@ public class Main { } private static class JsonReceiveMessageHandler implements Manager.ReceiveMessageHandler { + final Manager m; final ObjectMapper jsonProcessor; @@ -1257,6 +1253,7 @@ public class Main { } private static class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler { + final DBusConnection conn; public JsonDbusReceiveMessageHandler(Manager m, DBusConnection conn) { @@ -1264,13 +1261,6 @@ public class Main { this.conn = conn; } - @Override - public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) { - super.handleMessage(envelope, content, exception); - - sendReceivedMessageToDbus(envelope, content, conn, m); - } - private static void sendReceivedMessageToDbus(SignalServiceEnvelope envelope, SignalServiceContent content, DBusConnection conn, Manager m) { if (envelope.isReceipt()) { try { @@ -1311,5 +1301,12 @@ public class Main { } } } + + @Override + public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) { + super.handleMessage(envelope, content, exception); + + sendReceivedMessageToDbus(envelope, content, conn, m); + } } }