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]
### Breaking changes
- 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
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 java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
public class ListGroupsCommand implements JsonRpcLocalCommand {
@ -42,6 +43,14 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
.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(
PlainTextWriter writer, Manager m, GroupInfo group, boolean detailed
) {
@ -86,10 +95,10 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
group.getDescription(),
group.isMember(m.getSelfRecipientId()),
group.isBlocked(),
resolveMembers(m, group.getMembers()),
resolveMembers(m, group.getPendingMembers()),
resolveMembers(m, group.getRequestingMembers()),
resolveMembers(m, group.getAdminMembers()),
resolveJsonMembers(m, group.getMembers()),
resolveJsonMembers(m, group.getPendingMembers()),
resolveJsonMembers(m, group.getRequestingMembers()),
resolveJsonMembers(m, group.getAdminMembers()),
groupInviteLink == null ? null : groupInviteLink.getUrl());
}).collect(Collectors.toList());
@ -105,17 +114,17 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
private static final class JsonGroup {
public String id;
public String name;
public String description;
public boolean isMember;
public boolean isBlocked;
public final String id;
public final String name;
public final String description;
public final boolean isMember;
public final boolean isBlocked;
public Set<String> members;
public Set<String> pendingMembers;
public Set<String> requestingMembers;
public Set<String> admins;
public String groupInviteLink;
public final Set<JsonGroupMember> members;
public final Set<JsonGroupMember> pendingMembers;
public final Set<JsonGroupMember> requestingMembers;
public final Set<JsonGroupMember> admins;
public final String groupInviteLink;
public JsonGroup(
String id,
@ -123,10 +132,10 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
String description,
boolean isMember,
boolean isBlocked,
Set<String> members,
Set<String> pendingMembers,
Set<String> requestingMembers,
Set<String> admins,
Set<JsonGroupMember> members,
Set<JsonGroupMember> pendingMembers,
Set<JsonGroupMember> requestingMembers,
Set<JsonGroupMember> admins,
String groupInviteLink
) {
this.id = id;
@ -142,4 +151,15 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
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;
}
}
}