1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
4 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
6 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
7 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
8 import org
.asamk
.signal
.manager
.Manager
;
9 import org
.asamk
.signal
.manager
.api
.UserStatus
;
10 import org
.asamk
.signal
.output
.JsonWriter
;
11 import org
.asamk
.signal
.output
.OutputWriter
;
12 import org
.asamk
.signal
.output
.PlainTextWriter
;
13 import org
.slf4j
.Logger
;
14 import org
.slf4j
.LoggerFactory
;
16 import java
.io
.IOException
;
17 import java
.util
.HashSet
;
20 public class GetUserStatusCommand
implements JsonRpcLocalCommand
{
22 private final static Logger logger
= LoggerFactory
.getLogger(GetUserStatusCommand
.class);
25 public String
getName() {
26 return "getUserStatus";
30 public void attachToSubparser(final Subparser subparser
) {
31 subparser
.help("Check if the specified phone number/s have been registered");
32 subparser
.addArgument("recipient").help("Phone number").nargs("+");
36 public void handleCommand(
37 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
38 ) throws CommandException
{
39 // Get a map of registration statuses
40 Map
<String
, UserStatus
> registered
;
42 registered
= m
.getUserStatus(new HashSet
<>(ns
.getList("recipient")));
43 } catch (IOException e
) {
44 throw new IOErrorException("Unable to check if users are registered: "
47 + e
.getClass().getSimpleName()
52 if (outputWriter
instanceof JsonWriter jsonWriter
) {
54 var jsonUserStatuses
= registered
.entrySet().stream().map(entry
-> {
55 final var number
= entry
.getValue().number();
56 final var uuid
= entry
.getValue().uuid();
57 return new JsonUserStatus(entry
.getKey(), number
, uuid
== null ?
null : uuid
.toString(), uuid
!= null);
60 jsonWriter
.write(jsonUserStatuses
);
62 final var writer
= (PlainTextWriter
) outputWriter
;
64 for (var entry
: registered
.entrySet()) {
65 final var userStatus
= entry
.getValue();
66 writer
.println("{}: {}{}",
68 userStatus
.uuid() != null,
69 userStatus
.unrestrictedUnidentifiedAccess() ?
" (unrestricted sealed sender)" : "");
74 private record JsonUserStatus(String recipient
, String number
, String uuid
, boolean isRegistered
) {}