Add member uuids to listGroup json output

This commit is contained in:
AsamK 2021-08-22 13:01:51 +02:00
parent 5bbfd32598
commit 76942ea458
2 changed files with 40 additions and 18 deletions

View file

@ -3,6 +3,8 @@
## [Unreleased] ## [Unreleased]
### Breaking changes ### Breaking changes
- Removed deprecated `--json` parameter, use `--output=json` instead - Removed deprecated `--json` parameter, use `--output=json` instead
- Json output format of `listGroups` command changed:
Members are now arrays of `{"number":"...","uuid":"..."}` instead of arrays of strings.
- Removed deprecated fallback data paths, only `$XDG_DATA_HOME/signal-cli` is used now - Removed deprecated fallback data paths, only `$XDG_DATA_HOME/signal-cli` is used now
For those still using the old paths (`$HOME/.config/signal`, `$HOME/.config/textsecure`) you need to move those to the new location. For those still using the old paths (`$HOME/.config/signal`, `$HOME/.config/textsecure`) you need to move those to the new location.

View file

@ -16,6 +16,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ListGroupsCommand implements JsonRpcLocalCommand { public class ListGroupsCommand implements JsonRpcLocalCommand {
@ -42,6 +43,14 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
private static Set<JsonGroupMember> resolveJsonMembers(Manager m, Set<RecipientId> addresses) {
return addresses.stream()
.map(m::resolveSignalServiceAddress)
.map(address -> new JsonGroupMember(address.getNumber().orNull(),
address.getUuid().transform(UUID::toString).orNull()))
.collect(Collectors.toSet());
}
private static void printGroupPlainText( private static void printGroupPlainText(
PlainTextWriter writer, Manager m, GroupInfo group, boolean detailed PlainTextWriter writer, Manager m, GroupInfo group, boolean detailed
) { ) {
@ -86,10 +95,10 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
group.getDescription(), group.getDescription(),
group.isMember(m.getSelfRecipientId()), group.isMember(m.getSelfRecipientId()),
group.isBlocked(), group.isBlocked(),
resolveMembers(m, group.getMembers()), resolveJsonMembers(m, group.getMembers()),
resolveMembers(m, group.getPendingMembers()), resolveJsonMembers(m, group.getPendingMembers()),
resolveMembers(m, group.getRequestingMembers()), resolveJsonMembers(m, group.getRequestingMembers()),
resolveMembers(m, group.getAdminMembers()), resolveJsonMembers(m, group.getAdminMembers()),
groupInviteLink == null ? null : groupInviteLink.getUrl()); groupInviteLink == null ? null : groupInviteLink.getUrl());
}).collect(Collectors.toList()); }).collect(Collectors.toList());
@ -105,17 +114,17 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
private static final class JsonGroup { private static final class JsonGroup {
public String id; public final String id;
public String name; public final String name;
public String description; public final String description;
public boolean isMember; public final boolean isMember;
public boolean isBlocked; public final boolean isBlocked;
public Set<String> members; public final Set<JsonGroupMember> members;
public Set<String> pendingMembers; public final Set<JsonGroupMember> pendingMembers;
public Set<String> requestingMembers; public final Set<JsonGroupMember> requestingMembers;
public Set<String> admins; public final Set<JsonGroupMember> admins;
public String groupInviteLink; public final String groupInviteLink;
public JsonGroup( public JsonGroup(
String id, String id,
@ -123,10 +132,10 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
String description, String description,
boolean isMember, boolean isMember,
boolean isBlocked, boolean isBlocked,
Set<String> members, Set<JsonGroupMember> members,
Set<String> pendingMembers, Set<JsonGroupMember> pendingMembers,
Set<String> requestingMembers, Set<JsonGroupMember> requestingMembers,
Set<String> admins, Set<JsonGroupMember> admins,
String groupInviteLink String groupInviteLink
) { ) {
this.id = id; this.id = id;
@ -142,4 +151,15 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
this.groupInviteLink = groupInviteLink; this.groupInviteLink = groupInviteLink;
} }
} }
private static final class JsonGroupMember {
public final String number;
public final String uuid;
private JsonGroupMember(final String number, final String uuid) {
this.number = number;
this.uuid = uuid;
}
}
} }