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;
|
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;
|
return ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,17 +34,24 @@ public class SendCommand implements DbusCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int handleCommand(final Namespace ns, final Signal signal) {
|
public int handleCommand(final Namespace ns, final Signal signal) {
|
||||||
if ((ns.getList("recipient") == null || ns.getList("recipient").size() == 0) && (
|
final List<String> recipients = ns.getList("recipient");
|
||||||
ns.getBoolean("endsession") || ns.getString("group") == null
|
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("No recipients given");
|
||||||
System.err.println("Aborting sending.");
|
System.err.println("Aborting sending.");
|
||||||
return 1;
|
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 {
|
try {
|
||||||
signal.sendEndSessionMessage(ns.getList("recipient"));
|
signal.sendEndSessionMessage(recipients);
|
||||||
return 0;
|
return 0;
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError e) {
|
||||||
handleAssertionError(e);
|
handleAssertionError(e);
|
||||||
|
@ -72,10 +79,10 @@ public class SendCommand implements DbusCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (ns.getString("group") != null) {
|
if (groupIdString != null) {
|
||||||
byte[] groupId;
|
byte[] groupId;
|
||||||
try {
|
try {
|
||||||
groupId = Util.decodeGroupId(ns.getString("group")).serialize();
|
groupId = Util.decodeGroupId(groupIdString).serialize();
|
||||||
} catch (GroupIdFormatException e) {
|
} catch (GroupIdFormatException e) {
|
||||||
handleGroupIdFormatException(e);
|
handleGroupIdFormatException(e);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -94,7 +101,7 @@ public class SendCommand implements DbusCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
long timestamp = signal.sendMessage(messageText, attachments, ns.getList("recipient"));
|
long timestamp = signal.sendMessage(messageText, attachments, recipients);
|
||||||
System.out.println(timestamp);
|
System.out.println(timestamp);
|
||||||
return 0;
|
return 0;
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError e) {
|
||||||
|
|
|
@ -47,28 +47,32 @@ public class SendReactionCommand implements LocalCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int handleCommand(final Namespace ns, final Manager m) {
|
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("No recipients given");
|
||||||
System.err.println("Aborting sending.");
|
System.err.println("Aborting sending.");
|
||||||
return 1;
|
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");
|
final String emoji = ns.getString("emoji");
|
||||||
boolean isRemove = ns.getBoolean("remove");
|
final boolean isRemove = ns.getBoolean("remove");
|
||||||
String targetAuthor = ns.getString("target_author");
|
final String targetAuthor = ns.getString("target_author");
|
||||||
long targetTimestamp = ns.getLong("target_timestamp");
|
final long targetTimestamp = ns.getLong("target_timestamp");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Pair<Long, List<SendMessageResult>> results;
|
final Pair<Long, List<SendMessageResult>> results;
|
||||||
if (ns.getString("group") != null) {
|
if (groupIdString != null) {
|
||||||
GroupId groupId = Util.decodeGroupId(ns.getString("group"));
|
GroupId groupId = Util.decodeGroupId(groupIdString);
|
||||||
results = m.sendGroupMessageReaction(emoji, isRemove, targetAuthor, targetTimestamp, groupId);
|
results = m.sendGroupMessageReaction(emoji, isRemove, targetAuthor, targetTimestamp, groupId);
|
||||||
} else {
|
} else {
|
||||||
results = m.sendMessageReaction(emoji,
|
results = m.sendMessageReaction(emoji, isRemove, targetAuthor, targetTimestamp, recipients);
|
||||||
isRemove,
|
|
||||||
targetAuthor,
|
|
||||||
targetTimestamp,
|
|
||||||
ns.getList("recipient"));
|
|
||||||
}
|
}
|
||||||
return handleTimestampAndSendMessageResults(results.first(), results.second());
|
return handleTimestampAndSendMessageResults(results.first(), results.second());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue