mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-02 20:40:38 +00:00
Added AsamK's suggestions
This commit is contained in:
parent
06ea285d14
commit
ac31901f31
5 changed files with 40 additions and 98 deletions
|
@ -44,6 +44,9 @@ Make request via user dbus.
|
||||||
*--dbus-system*::
|
*--dbus-system*::
|
||||||
Make request via system dbus.
|
Make request via system dbus.
|
||||||
|
|
||||||
|
*-o* OUTPUT-MODE, *--output* OUTPUT-MODE::
|
||||||
|
Specify if you want commands to output in either "plain-text" mode or in "json". Defaults to "plain-text"
|
||||||
|
|
||||||
== Commands
|
== Commands
|
||||||
|
|
||||||
=== register
|
=== register
|
||||||
|
@ -126,12 +129,10 @@ Use listDevices to see the deviceIds.
|
||||||
|
|
||||||
=== getUserStatus
|
=== getUserStatus
|
||||||
|
|
||||||
Uses a list of phone numbers to determine the statuses of those users. Shows if they are registered on the Signal Servers or not.
|
Uses a list of phone numbers to determine the statuses of those users. Shows if they are registered on the Signal Servers or not. In json mode this is outputted as a list of objects.
|
||||||
|
|
||||||
[NUMBER [NUMBER ...]]::
|
[NUMBER [NUMBER ...]]::
|
||||||
One or more numbers to check.
|
One or more numbers to check.
|
||||||
*--j*, *--json*::
|
|
||||||
Output the statuses as an array of json objects.
|
|
||||||
|
|
||||||
=== send
|
=== send
|
||||||
|
|
||||||
|
@ -177,15 +178,13 @@ Remove a reaction.
|
||||||
=== receive
|
=== receive
|
||||||
|
|
||||||
Query the server for new messages.
|
Query the server for new messages.
|
||||||
New messages are printed on standardoutput and attachments are downloaded to the config directory.
|
New messages are printed on standard output and attachments are downloaded to the config directory. In json mode this is outputted as one json object per line.
|
||||||
|
|
||||||
*-t* TIMEOUT, *--timeout* TIMEOUT::
|
*-t* TIMEOUT, *--timeout* TIMEOUT::
|
||||||
Number of seconds to wait for new messages (negative values disable timeout).
|
Number of seconds to wait for new messages (negative values disable timeout).
|
||||||
Default is 5 seconds.
|
Default is 5 seconds.
|
||||||
*--ignore-attachments*::
|
*--ignore-attachments*::
|
||||||
Don’t download attachments of received messages.
|
Don’t download attachments of received messages.
|
||||||
*--j*, *--json*::
|
|
||||||
Output received messages in json format, one object per line.
|
|
||||||
|
|
||||||
=== joinGroup
|
=== joinGroup
|
||||||
|
|
||||||
|
@ -222,14 +221,11 @@ Specify the recipient group ID in base64 encoding.
|
||||||
|
|
||||||
=== listGroups
|
=== listGroups
|
||||||
|
|
||||||
Show a list of known groups and related information.
|
Show a list of known groups and related information. In json mode this is outputted as an list of objects and is always in detailed mode.
|
||||||
|
|
||||||
*-d*, *--detailed*::
|
*-d*, *--detailed*::
|
||||||
Include the list of members of each group and the group invite link.
|
Include the list of members of each group and the group invite link.
|
||||||
|
|
||||||
*--j*, *--json*::
|
|
||||||
Output group information as a list of json objects.
|
|
||||||
|
|
||||||
=== listIdentities
|
=== listIdentities
|
||||||
|
|
||||||
List all known identity keys and their trust status, fingerprint and safety number.
|
List all known identity keys and their trust status, fingerprint and safety number.
|
||||||
|
|
|
@ -283,6 +283,9 @@ public class Main {
|
||||||
mut.addArgument("--dbus").help("Make request via user dbus.").action(Arguments.storeTrue());
|
mut.addArgument("--dbus").help("Make request via user dbus.").action(Arguments.storeTrue());
|
||||||
mut.addArgument("--dbus-system").help("Make request via system dbus.").action(Arguments.storeTrue());
|
mut.addArgument("--dbus-system").help("Make request via system dbus.").action(Arguments.storeTrue());
|
||||||
|
|
||||||
|
parser.addArgument("-o", "--output").help("Choose to output in plain text or JSON")
|
||||||
|
.choices("plain-text", "json").setDefault("plain-text");
|
||||||
|
|
||||||
Subparsers subparsers = parser.addSubparsers()
|
Subparsers subparsers = parser.addSubparsers()
|
||||||
.title("subcommands")
|
.title("subcommands")
|
||||||
.dest("command")
|
.dest("command")
|
||||||
|
|
|
@ -21,9 +21,6 @@ public class GetUserStatusCommand implements LocalCommand {
|
||||||
public void attachToSubparser(final Subparser subparser) {
|
public void attachToSubparser(final Subparser subparser) {
|
||||||
subparser.addArgument("number").help("Phone number").nargs("+");
|
subparser.addArgument("number").help("Phone number").nargs("+");
|
||||||
subparser.help("Check if the specified phone number/s have been registered");
|
subparser.help("Check if the specified phone number/s have been registered");
|
||||||
subparser.addArgument("-j", "--json")
|
|
||||||
.help("Output received messages in json format, one json object per line.")
|
|
||||||
.action(Arguments.storeTrue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -47,7 +44,7 @@ public class GetUserStatusCommand implements LocalCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
if (ns.getBoolean("json")) {
|
if (ns.getString("output").equals("json")) {
|
||||||
List<JsonIsRegistered> objects = registered.entrySet()
|
List<JsonIsRegistered> objects = registered.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
.map(entry -> new JsonIsRegistered(entry.getKey(), entry.getValue()))
|
.map(entry -> new JsonIsRegistered(entry.getKey(), entry.getValue()))
|
||||||
|
|
|
@ -16,36 +16,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ListGroupsCommand implements LocalCommand {
|
public class ListGroupsCommand implements LocalCommand {
|
||||||
|
|
||||||
private enum MembersType {
|
private static Set<String> resolveMembers(Manager m, Set<SignalServiceAddress> addresses) {
|
||||||
MEMBERS,
|
return addresses.stream().map(m::resolveSignalServiceAddress)
|
||||||
PENDING_MEMBERS,
|
|
||||||
REQUESTING_MEMBERS,
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Set<String> getMembersSet(Manager m, GroupInfo group, MembersType type) {
|
|
||||||
Set<SignalServiceAddress> members;
|
|
||||||
switch (type) {
|
|
||||||
case MEMBERS:
|
|
||||||
members = group.getMembers();
|
|
||||||
break;
|
|
||||||
case PENDING_MEMBERS:
|
|
||||||
members = group.getPendingMembers();
|
|
||||||
break;
|
|
||||||
case REQUESTING_MEMBERS:
|
|
||||||
members = group.getRequestingMembers();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return Collections.emptySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
return members.stream().map(m::resolveSignalServiceAddress)
|
|
||||||
.map(SignalServiceAddress::getLegacyIdentifier)
|
.map(SignalServiceAddress::getLegacyIdentifier)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
@ -72,9 +50,9 @@ public class ListGroupsCommand implements LocalCommand {
|
||||||
group.getTitle(),
|
group.getTitle(),
|
||||||
group.isMember(m.getSelfAddress()),
|
group.isMember(m.getSelfAddress()),
|
||||||
group.isBlocked(),
|
group.isBlocked(),
|
||||||
getMembersSet(m, group, MembersType.MEMBERS),
|
resolveMembers(m, group.getMembers()),
|
||||||
getMembersSet(m, group, MembersType.PENDING_MEMBERS),
|
resolveMembers(m, group.getPendingMembers()),
|
||||||
getMembersSet(m, group, MembersType.REQUESTING_MEMBERS),
|
resolveMembers(m, group.getRequestingMembers()),
|
||||||
groupInviteLink == null ? '-' : groupInviteLink.getUrl()));
|
groupInviteLink == null ? '-' : groupInviteLink.getUrl()));
|
||||||
} else {
|
} else {
|
||||||
System.out.println(String.format("Id: %s Name: %s Active: %s Blocked: %b",
|
System.out.println(String.format("Id: %s Name: %s Active: %s Blocked: %b",
|
||||||
|
@ -87,11 +65,10 @@ public class ListGroupsCommand implements LocalCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void attachToSubparser(final Subparser subparser) {
|
public void attachToSubparser(final Subparser subparser) {
|
||||||
subparser.addArgument("-d", "--detailed").action(Arguments.storeTrue()).help("List members of each group");
|
subparser.addArgument("-d", "--detailed").action(Arguments.storeTrue())
|
||||||
subparser.help("List group name and ids");
|
.help("List the members and group invite links of each group");
|
||||||
subparser.addArgument("-j", "--json")
|
|
||||||
.help("Output received messages in json format, one json object per line.")
|
subparser.help("List group information including names, ids, active status, blocked status and members");
|
||||||
.action(Arguments.storeTrue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,42 +78,29 @@ public class ListGroupsCommand implements LocalCommand {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<GroupInfo> groups = m.getGroups();
|
if (ns.getString("output").equals("json")) {
|
||||||
boolean detailed = ns.getBoolean("detailed");
|
|
||||||
|
|
||||||
if (ns.getBoolean("json")) {
|
|
||||||
final ObjectMapper jsonProcessor = new ObjectMapper();
|
final ObjectMapper jsonProcessor = new ObjectMapper();
|
||||||
jsonProcessor.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
jsonProcessor.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||||
jsonProcessor.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
|
jsonProcessor.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
|
||||||
|
|
||||||
if (detailed) {
|
List<JsonGroup> objects = new ArrayList<>();
|
||||||
List<JsonGroupDetailed> objects = new ArrayList<>();
|
for (GroupInfo group : m.getGroups()) {
|
||||||
for (GroupInfo group : groups) {
|
final GroupInviteLinkUrl groupInviteLink = group.getGroupInviteLink();
|
||||||
final GroupInviteLinkUrl groupInviteLink = group.getGroupInviteLink();
|
|
||||||
|
|
||||||
objects.add(new JsonGroupDetailed(group.getGroupId().toBase64(),
|
objects.add(new JsonGroup(group.getGroupId().toBase64(),
|
||||||
group.getTitle(),
|
group.getTitle(),
|
||||||
group.isMember(m.getSelfAddress()),
|
group.isMember(m.getSelfAddress()),
|
||||||
group.isBlocked(),
|
group.isBlocked(),
|
||||||
getMembersSet(m, group, MembersType.MEMBERS),
|
resolveMembers(m, group.getMembers()),
|
||||||
getMembersSet(m, group, MembersType.PENDING_MEMBERS),
|
resolveMembers(m, group.getPendingMembers()),
|
||||||
getMembersSet(m, group, MembersType.REQUESTING_MEMBERS),
|
resolveMembers(m, group.getRequestingMembers()),
|
||||||
groupInviteLink == null ? null : groupInviteLink.getUrl()));
|
groupInviteLink == null ? null : groupInviteLink.getUrl()));
|
||||||
}
|
|
||||||
|
|
||||||
return printGroupsJson(jsonProcessor, objects);
|
|
||||||
} else {
|
|
||||||
List<JsonGroup> objects = groups.stream().map(
|
|
||||||
group -> new JsonGroup(group.getGroupId().toBase64(),
|
|
||||||
group.getTitle(),
|
|
||||||
group.isMember(m.getSelfAddress()),
|
|
||||||
group.isBlocked()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
return printGroupsJson(jsonProcessor, objects);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return printGroupsJson(jsonProcessor, objects);
|
||||||
} else {
|
} else {
|
||||||
for (GroupInfo group : groups) {
|
boolean detailed = ns.getBoolean("detailed");
|
||||||
|
for (GroupInfo group : m.getGroups()) {
|
||||||
printGroupPlainText(m, group, detailed);
|
printGroupPlainText(m, group, detailed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,29 +115,14 @@ public class ListGroupsCommand implements LocalCommand {
|
||||||
public boolean isMember;
|
public boolean isMember;
|
||||||
public boolean isBlocked;
|
public boolean isBlocked;
|
||||||
|
|
||||||
public JsonGroup(String id, String name, boolean isMember, boolean isBlocked) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
this.isMember = isMember;
|
|
||||||
this.isBlocked = isBlocked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class JsonGroupDetailed {
|
|
||||||
|
|
||||||
public String id;
|
|
||||||
public String name;
|
|
||||||
public boolean isMember;
|
|
||||||
public boolean isBlocked;
|
|
||||||
|
|
||||||
public Set<String> members;
|
public Set<String> members;
|
||||||
public Set<String> pendingMembers;
|
public Set<String> pendingMembers;
|
||||||
public Set<String> requestingMembers;
|
public Set<String> requestingMembers;
|
||||||
public String groupInviteLink;
|
public String groupInviteLink;
|
||||||
|
|
||||||
public JsonGroupDetailed(String id, String name, boolean isMember, boolean isBlocked,
|
public JsonGroup(String id, String name, boolean isMember, boolean isBlocked,
|
||||||
Set<String> members, Set<String> pendingMembers,
|
Set<String> members, Set<String> pendingMembers,
|
||||||
Set<String> requestingMembers, String groupInviteLink)
|
Set<String> requestingMembers, String groupInviteLink)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
|
@ -35,14 +35,11 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
|
||||||
subparser.addArgument("--ignore-attachments")
|
subparser.addArgument("--ignore-attachments")
|
||||||
.help("Don’t download attachments of received messages.")
|
.help("Don’t download attachments of received messages.")
|
||||||
.action(Arguments.storeTrue());
|
.action(Arguments.storeTrue());
|
||||||
subparser.addArgument("-j", "--json")
|
|
||||||
.help("Output received messages in json format, one json object per line.")
|
|
||||||
.action(Arguments.storeTrue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int handleCommand(final Namespace ns, final Signal signal, DBusConnection dbusconnection) {
|
public int handleCommand(final Namespace ns, final Signal signal, DBusConnection dbusconnection) {
|
||||||
final ObjectMapper jsonProcessor;
|
final ObjectMapper jsonProcessor;
|
||||||
if (ns.getBoolean("json")) {
|
if (ns.getString("output").equals("json")) {
|
||||||
jsonProcessor = new ObjectMapper();
|
jsonProcessor = new ObjectMapper();
|
||||||
jsonProcessor.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
jsonProcessor.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||||
jsonProcessor.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
|
jsonProcessor.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
|
||||||
|
@ -161,7 +158,7 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
|
||||||
}
|
}
|
||||||
boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
|
boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
|
||||||
try {
|
try {
|
||||||
final Manager.ReceiveMessageHandler handler = ns.getBoolean("json")
|
final Manager.ReceiveMessageHandler handler = ns.getString("output").equals("json")
|
||||||
? new JsonReceiveMessageHandler(m)
|
? new JsonReceiveMessageHandler(m)
|
||||||
: new ReceiveMessageHandler(m);
|
: new ReceiveMessageHandler(m);
|
||||||
m.receiveMessages((long) (timeout * 1000),
|
m.receiveMessages((long) (timeout * 1000),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue