Include unrestricted unidentified access state in getUserStatus response

This commit is contained in:
AsamK 2022-05-17 20:39:06 +02:00
parent 376fcba9ec
commit bb9d44811c
6 changed files with 36 additions and 24 deletions

View file

@ -6,7 +6,7 @@ import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.Pair;
import org.asamk.signal.manager.api.UserStatus;
import org.asamk.signal.output.JsonWriter;
import org.asamk.signal.output.OutputWriter;
import org.asamk.signal.output.PlainTextWriter;
@ -16,7 +16,6 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.HashSet;
import java.util.Map;
import java.util.UUID;
public class GetUserStatusCommand implements JsonRpcLocalCommand {
@ -38,9 +37,9 @@ public class GetUserStatusCommand implements JsonRpcLocalCommand {
final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException {
// Get a map of registration statuses
Map<String, Pair<String, UUID>> registered;
Map<String, UserStatus> registered;
try {
registered = m.areUsersRegistered(new HashSet<>(ns.getList("recipient")));
registered = m.getUserStatus(new HashSet<>(ns.getList("recipient")));
} catch (IOException e) {
throw new IOErrorException("Unable to check if users are registered: "
+ e.getMessage()
@ -53,8 +52,8 @@ public class GetUserStatusCommand implements JsonRpcLocalCommand {
if (outputWriter instanceof JsonWriter jsonWriter) {
var jsonUserStatuses = registered.entrySet().stream().map(entry -> {
final var number = entry.getValue().first();
final var uuid = entry.getValue().second();
final var number = entry.getValue().number();
final var uuid = entry.getValue().uuid();
return new JsonUserStatus(entry.getKey(), number, uuid == null ? null : uuid.toString(), uuid != null);
}).toList();
@ -63,8 +62,11 @@ public class GetUserStatusCommand implements JsonRpcLocalCommand {
final var writer = (PlainTextWriter) outputWriter;
for (var entry : registered.entrySet()) {
final var uuid = entry.getValue().second();
writer.println("{}: {}", entry.getKey(), uuid != null);
final var userStatus = entry.getValue();
writer.println("{}: {}{}",
entry.getKey(),
userStatus.uuid() != null,
userStatus.unrestrictedUnidentifiedAccess() ? " (unrestricted sealed sender)" : "");
}
}
}

View file

@ -22,6 +22,7 @@ import org.asamk.signal.manager.api.StickerPackInvalidException;
import org.asamk.signal.manager.api.StickerPackUrl;
import org.asamk.signal.manager.api.TypingAction;
import org.asamk.signal.manager.api.UpdateGroup;
import org.asamk.signal.manager.api.UserStatus;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
import org.asamk.signal.manager.groups.GroupNotFoundException;
@ -53,7 +54,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.function.Supplier;
@ -87,14 +87,16 @@ public class DbusManagerImpl implements Manager {
}
@Override
public Map<String, Pair<String, UUID>> areUsersRegistered(final Set<String> numbers) throws IOException {
public Map<String, UserStatus> getUserStatus(final Set<String> numbers) throws IOException {
final var numbersList = new ArrayList<>(numbers);
final var registered = signal.isRegistered(numbersList);
final var result = new HashMap<String, Pair<String, UUID>>();
final var result = new HashMap<String, UserStatus>();
for (var i = 0; i < numbersList.size(); i++) {
result.put(numbersList.get(i),
new Pair<>(numbersList.get(i), registered.get(i) ? RecipientAddress.UNKNOWN_UUID : null));
new UserStatus(numbersList.get(i),
registered.get(i) ? RecipientAddress.UNKNOWN_UUID : null,
false));
}
return result;
}

View file

@ -19,6 +19,7 @@ import org.asamk.signal.manager.api.StickerPackInvalidException;
import org.asamk.signal.manager.api.TypingAction;
import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.api.UpdateGroup;
import org.asamk.signal.manager.api.UserStatus;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
import org.asamk.signal.manager.groups.GroupLinkState;
@ -53,7 +54,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -641,17 +641,14 @@ public class DbusSignalImpl implements Signal {
return List.of();
}
Map<String, Pair<String, UUID>> registered;
Map<String, UserStatus> registered;
try {
registered = m.areUsersRegistered(new HashSet<>(numbers));
registered = m.getUserStatus(new HashSet<>(numbers));
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
}
return numbers.stream().map(number -> {
var uuid = registered.get(number).second();
return uuid != null;
}).toList();
return numbers.stream().map(number -> registered.get(number).uuid() != null).toList();
}
@Override