mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Move recipients/group argument check to send commands
This commit is contained in:
parent
9e061c8667
commit
b31e97dd2d
3 changed files with 31 additions and 25 deletions
|
@ -93,11 +93,6 @@ public class Main {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (ns.getList("recipient") != null && !ns.getList("recipient").isEmpty() && ns.getString("group") != null) {
|
||||
System.err.println("You cannot specify recipients by phone number and groups at the same time");
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
return ns;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,17 +34,24 @@ public class SendCommand implements DbusCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Signal signal) {
|
||||
if ((ns.getList("recipient") == null || ns.getList("recipient").size() == 0) && (
|
||||
ns.getBoolean("endsession") || ns.getString("group") == null
|
||||
)) {
|
||||
final List<String> recipients = ns.getList("recipient");
|
||||
final Boolean isEndSession = ns.getBoolean("endsession");
|
||||
final String groupIdString = ns.getString("group");
|
||||
|
||||
final boolean noRecipients = recipients == null || recipients.isEmpty();
|
||||
if ((noRecipients && isEndSession) || (noRecipients && groupIdString == null)) {
|
||||
System.err.println("No recipients given");
|
||||
System.err.println("Aborting sending.");
|
||||
return 1;
|
||||
}
|
||||
if (!noRecipients && groupIdString != null) {
|
||||
System.err.println("You cannot specify recipients by phone number and groups at the same time");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ns.getBoolean("endsession")) {
|
||||
if (isEndSession) {
|
||||
try {
|
||||
signal.sendEndSessionMessage(ns.getList("recipient"));
|
||||
signal.sendEndSessionMessage(recipients);
|
||||
return 0;
|
||||
} catch (AssertionError e) {
|
||||
handleAssertionError(e);
|
||||
|
@ -72,10 +79,10 @@ public class SendCommand implements DbusCommand {
|
|||
}
|
||||
|
||||
try {
|
||||
if (ns.getString("group") != null) {
|
||||
if (groupIdString != null) {
|
||||
byte[] groupId;
|
||||
try {
|
||||
groupId = Util.decodeGroupId(ns.getString("group")).serialize();
|
||||
groupId = Util.decodeGroupId(groupIdString).serialize();
|
||||
} catch (GroupIdFormatException e) {
|
||||
handleGroupIdFormatException(e);
|
||||
return 1;
|
||||
|
@ -94,7 +101,7 @@ public class SendCommand implements DbusCommand {
|
|||
}
|
||||
|
||||
try {
|
||||
long timestamp = signal.sendMessage(messageText, attachments, ns.getList("recipient"));
|
||||
long timestamp = signal.sendMessage(messageText, attachments, recipients);
|
||||
System.out.println(timestamp);
|
||||
return 0;
|
||||
} catch (AssertionError e) {
|
||||
|
|
|
@ -47,28 +47,32 @@ public class SendReactionCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if ((ns.getList("recipient") == null || ns.getList("recipient").size() == 0) && ns.getString("group") == null) {
|
||||
final List<String> recipients = ns.getList("recipient");
|
||||
final String groupIdString = ns.getString("group");
|
||||
|
||||
final boolean noRecipients = recipients == null || recipients.isEmpty();
|
||||
if (noRecipients && groupIdString == null) {
|
||||
System.err.println("No recipients given");
|
||||
System.err.println("Aborting sending.");
|
||||
return 1;
|
||||
}
|
||||
if (!noRecipients && groupIdString != null) {
|
||||
System.err.println("You cannot specify recipients by phone number and groups at the same time");
|
||||
return 1;
|
||||
}
|
||||
|
||||
String emoji = ns.getString("emoji");
|
||||
boolean isRemove = ns.getBoolean("remove");
|
||||
String targetAuthor = ns.getString("target_author");
|
||||
long targetTimestamp = ns.getLong("target_timestamp");
|
||||
final String emoji = ns.getString("emoji");
|
||||
final boolean isRemove = ns.getBoolean("remove");
|
||||
final String targetAuthor = ns.getString("target_author");
|
||||
final long targetTimestamp = ns.getLong("target_timestamp");
|
||||
|
||||
try {
|
||||
final Pair<Long, List<SendMessageResult>> results;
|
||||
if (ns.getString("group") != null) {
|
||||
GroupId groupId = Util.decodeGroupId(ns.getString("group"));
|
||||
if (groupIdString != null) {
|
||||
GroupId groupId = Util.decodeGroupId(groupIdString);
|
||||
results = m.sendGroupMessageReaction(emoji, isRemove, targetAuthor, targetTimestamp, groupId);
|
||||
} else {
|
||||
results = m.sendMessageReaction(emoji,
|
||||
isRemove,
|
||||
targetAuthor,
|
||||
targetTimestamp,
|
||||
ns.getList("recipient"));
|
||||
results = m.sendMessageReaction(emoji, isRemove, targetAuthor, targetTimestamp, recipients);
|
||||
}
|
||||
return handleTimestampAndSendMessageResults(results.first(), results.second());
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue