mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 02:50:39 +00:00
Separate DbusSignal implementation from Manager
This commit is contained in:
parent
d08508e6ef
commit
1e0aa8929d
8 changed files with 332 additions and 182 deletions
|
@ -6,6 +6,7 @@ import net.sourceforge.argparse4j.inf.Subparser;
|
|||
|
||||
import org.asamk.signal.DbusReceiveMessageHandler;
|
||||
import org.asamk.signal.JsonDbusReceiveMessageHandler;
|
||||
import org.asamk.signal.dbus.DbusSignalImpl;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
|
@ -48,7 +49,7 @@ public class DaemonCommand implements LocalCommand {
|
|||
busType = DBusConnection.DBusBusType.SESSION;
|
||||
}
|
||||
conn = DBusConnection.getConnection(busType);
|
||||
conn.exportObject(SIGNAL_OBJECTPATH, m);
|
||||
conn.exportObject(SIGNAL_OBJECTPATH, new DbusSignalImpl(m));
|
||||
conn.requestBusName(SIGNAL_BUSNAME);
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Missing native library dependency for dbus service: " + e.getMessage());
|
||||
|
|
|
@ -5,15 +5,10 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
|||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.manager.AttachmentInvalidException;
|
||||
import org.asamk.signal.manager.GroupNotFoundException;
|
||||
import org.asamk.signal.manager.NotAGroupMemberException;
|
||||
import org.asamk.signal.util.GroupIdFormatException;
|
||||
import org.asamk.signal.util.IOUtils;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
@ -21,13 +16,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
||||
import static org.asamk.signal.util.ErrorUtils.handleDBusExecutionException;
|
||||
import static org.asamk.signal.util.ErrorUtils.handleEncapsulatedExceptions;
|
||||
import static org.asamk.signal.util.ErrorUtils.handleGroupIdFormatException;
|
||||
import static org.asamk.signal.util.ErrorUtils.handleGroupNotFoundException;
|
||||
import static org.asamk.signal.util.ErrorUtils.handleIOException;
|
||||
import static org.asamk.signal.util.ErrorUtils.handleInvalidNumberException;
|
||||
import static org.asamk.signal.util.ErrorUtils.handleNotAGroupMemberException;
|
||||
|
||||
public class SendCommand implements DbusCommand {
|
||||
|
||||
|
@ -65,20 +54,11 @@ public class SendCommand implements DbusCommand {
|
|||
try {
|
||||
signal.sendEndSessionMessage(ns.getList("recipient"));
|
||||
return 0;
|
||||
} catch (IOException e) {
|
||||
handleIOException(e);
|
||||
return 3;
|
||||
} catch (EncapsulatedExceptions e) {
|
||||
handleEncapsulatedExceptions(e);
|
||||
return 3;
|
||||
} catch (AssertionError e) {
|
||||
handleAssertionError(e);
|
||||
return 1;
|
||||
} catch (DBusExecutionException e) {
|
||||
handleDBusExecutionException(e);
|
||||
return 1;
|
||||
} catch (InvalidNumberException e) {
|
||||
handleInvalidNumberException(e);
|
||||
System.err.println("Failed to send message: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -94,47 +74,42 @@ public class SendCommand implements DbusCommand {
|
|||
}
|
||||
}
|
||||
|
||||
List<String> attachments = ns.getList("attachment");
|
||||
if (attachments == null) {
|
||||
attachments = new ArrayList<>();
|
||||
}
|
||||
|
||||
try {
|
||||
List<String> attachments = ns.getList("attachment");
|
||||
if (attachments == null) {
|
||||
attachments = new ArrayList<>();
|
||||
}
|
||||
long timestamp;
|
||||
if (ns.getString("group") != null) {
|
||||
byte[] groupId = Util.decodeGroupId(ns.getString("group"));
|
||||
timestamp = signal.sendGroupMessage(messageText, attachments, groupId);
|
||||
} else {
|
||||
timestamp = signal.sendMessage(messageText, attachments, ns.getList("recipient"));
|
||||
byte[] groupId;
|
||||
try {
|
||||
groupId = Util.decodeGroupId(ns.getString("group"));
|
||||
} catch (GroupIdFormatException e) {
|
||||
handleGroupIdFormatException(e);
|
||||
return 1;
|
||||
}
|
||||
|
||||
long timestamp = signal.sendGroupMessage(messageText, attachments, groupId);
|
||||
System.out.println(timestamp);
|
||||
return 0;
|
||||
}
|
||||
System.out.println(timestamp);
|
||||
return 0;
|
||||
} catch (IOException e) {
|
||||
handleIOException(e);
|
||||
return 3;
|
||||
} catch (EncapsulatedExceptions e) {
|
||||
handleEncapsulatedExceptions(e);
|
||||
return 3;
|
||||
} catch (AssertionError e) {
|
||||
handleAssertionError(e);
|
||||
return 1;
|
||||
} catch (GroupNotFoundException e) {
|
||||
handleGroupNotFoundException(e);
|
||||
} catch (DBusExecutionException e) {
|
||||
System.err.println("Failed to send message: " + e.getMessage());
|
||||
return 1;
|
||||
} catch (NotAGroupMemberException e) {
|
||||
handleNotAGroupMemberException(e);
|
||||
return 1;
|
||||
} catch (AttachmentInvalidException e) {
|
||||
System.err.println("Failed to add attachment: " + e.getMessage());
|
||||
System.err.println("Aborting sending.");
|
||||
}
|
||||
|
||||
try {
|
||||
long timestamp = signal.sendMessage(messageText, attachments, ns.getList("recipient"));
|
||||
System.out.println(timestamp);
|
||||
return 0;
|
||||
} catch (AssertionError e) {
|
||||
handleAssertionError(e);
|
||||
return 1;
|
||||
} catch (DBusExecutionException e) {
|
||||
handleDBusExecutionException(e);
|
||||
return 1;
|
||||
} catch (GroupIdFormatException e) {
|
||||
handleGroupIdFormatException(e);
|
||||
return 1;
|
||||
} catch (InvalidNumberException e) {
|
||||
handleInvalidNumberException(e);
|
||||
System.err.println("Failed to send message: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,25 +4,16 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
|||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.manager.AttachmentInvalidException;
|
||||
import org.asamk.signal.manager.GroupNotFoundException;
|
||||
import org.asamk.signal.manager.NotAGroupMemberException;
|
||||
import org.asamk.signal.util.GroupIdFormatException;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.whispersystems.util.Base64;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.asamk.signal.util.ErrorUtils.handleEncapsulatedExceptions;
|
||||
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
||||
import static org.asamk.signal.util.ErrorUtils.handleGroupIdFormatException;
|
||||
import static org.asamk.signal.util.ErrorUtils.handleGroupNotFoundException;
|
||||
import static org.asamk.signal.util.ErrorUtils.handleIOException;
|
||||
import static org.asamk.signal.util.ErrorUtils.handleInvalidNumberException;
|
||||
import static org.asamk.signal.util.ErrorUtils.handleNotAGroupMemberException;
|
||||
|
||||
public class UpdateGroupCommand implements DbusCommand {
|
||||
|
||||
|
@ -46,52 +37,48 @@ public class UpdateGroupCommand implements DbusCommand {
|
|||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
byte[] groupId = null;
|
||||
if (ns.getString("group") != null) {
|
||||
byte[] groupId = null;
|
||||
if (ns.getString("group") != null) {
|
||||
try {
|
||||
groupId = Util.decodeGroupId(ns.getString("group"));
|
||||
} catch (GroupIdFormatException e) {
|
||||
handleGroupIdFormatException(e);
|
||||
return 1;
|
||||
}
|
||||
if (groupId == null) {
|
||||
groupId = new byte[0];
|
||||
}
|
||||
String groupName = ns.getString("name");
|
||||
if (groupName == null) {
|
||||
groupName = "";
|
||||
}
|
||||
List<String> groupMembers = ns.getList("member");
|
||||
if (groupMembers == null) {
|
||||
groupMembers = new ArrayList<>();
|
||||
}
|
||||
String groupAvatar = ns.getString("avatar");
|
||||
if (groupAvatar == null) {
|
||||
groupAvatar = "";
|
||||
}
|
||||
}
|
||||
if (groupId == null) {
|
||||
groupId = new byte[0];
|
||||
}
|
||||
|
||||
String groupName = ns.getString("name");
|
||||
if (groupName == null) {
|
||||
groupName = "";
|
||||
}
|
||||
|
||||
List<String> groupMembers = ns.getList("member");
|
||||
if (groupMembers == null) {
|
||||
groupMembers = new ArrayList<>();
|
||||
}
|
||||
|
||||
String groupAvatar = ns.getString("avatar");
|
||||
if (groupAvatar == null) {
|
||||
groupAvatar = "";
|
||||
}
|
||||
|
||||
try {
|
||||
byte[] newGroupId = signal.updateGroup(groupId, groupName, groupMembers, groupAvatar);
|
||||
if (groupId.length != newGroupId.length) {
|
||||
System.out.println("Creating new group \"" + Base64.encodeBytes(newGroupId) + "\" …");
|
||||
}
|
||||
return 0;
|
||||
} catch (IOException e) {
|
||||
handleIOException(e);
|
||||
return 3;
|
||||
} catch (AttachmentInvalidException e) {
|
||||
} catch (AssertionError e) {
|
||||
handleAssertionError(e);
|
||||
return 1;
|
||||
} catch (Signal.Error.AttachmentInvalid e) {
|
||||
System.err.println("Failed to add avatar attachment for group\": " + e.getMessage());
|
||||
System.err.println("Aborting sending.");
|
||||
return 1;
|
||||
} catch (GroupNotFoundException e) {
|
||||
handleGroupNotFoundException(e);
|
||||
return 1;
|
||||
} catch (NotAGroupMemberException e) {
|
||||
handleNotAGroupMemberException(e);
|
||||
return 1;
|
||||
} catch (EncapsulatedExceptions e) {
|
||||
handleEncapsulatedExceptions(e);
|
||||
return 3;
|
||||
} catch (GroupIdFormatException e) {
|
||||
handleGroupIdFormatException(e);
|
||||
return 1;
|
||||
} catch (InvalidNumberException e) {
|
||||
handleInvalidNumberException(e);
|
||||
} catch (DBusExecutionException e) {
|
||||
System.err.println("Failed to send message: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue