diff --git a/cmd/signaldctl/README.md b/cmd/signaldctl/README.md index 6d44524..1dce4a2 100644 --- a/cmd/signaldctl/README.md +++ b/cmd/signaldctl/README.md @@ -31,4 +31,6 @@ signaldctl account create --verify --phone-number +15555555555 --code 999-999 ``` signaldctl message send --account +15555555555 --to +12024561414 --message "yo" -``` \ No newline at end of file +``` + +`--to` can also be a group ID \ No newline at end of file diff --git a/cmd/signaldctl/cmd/account/link/link-account.go b/cmd/signaldctl/cmd/account/link/link-account.go index 1868721..a819030 100644 --- a/cmd/signaldctl/cmd/account/link/link-account.go +++ b/cmd/signaldctl/cmd/account/link/link-account.go @@ -44,7 +44,7 @@ var ( } c := make(chan v0.LegacyResponse) go common.Signald.Listen(c) - uri := common.GetResponse(c, requestID) + uri := signald.GetLegacyResponse(c, requestID) if uri.Type != "linking_uri" { log.Fatalf("unexpected response from signald when requesting link: %+v", uri) } @@ -80,7 +80,7 @@ var ( return } - finish := common.GetResponse(c, requestID) + finish := signald.GetLegacyResponse(c, requestID) if finish.Type == "linking_successful" { log.Println("linking successful") return diff --git a/cmd/signaldctl/cmd/account/register/register-account.go b/cmd/signaldctl/cmd/account/register/register-account.go index 76b8e50..534f9a7 100644 --- a/cmd/signaldctl/cmd/account/register/register-account.go +++ b/cmd/signaldctl/cmd/account/register/register-account.go @@ -50,7 +50,7 @@ var ( } c := make(chan v0.LegacyResponse) go common.Signald.Listen(c) - response := common.GetResponse(c, requestID) + response := signald.GetLegacyResponse(c, requestID) if response.Type == "verification_required" { log.Println("verification code requested. submit with: signaldctl account verify --phone-number", phoneNumber, "--code XXX-XXX") } else { diff --git a/cmd/signaldctl/cmd/account/verify/verify-account.go b/cmd/signaldctl/cmd/account/verify/verify-account.go index 2d8e066..7aa5c47 100644 --- a/cmd/signaldctl/cmd/account/verify/verify-account.go +++ b/cmd/signaldctl/cmd/account/verify/verify-account.go @@ -53,9 +53,9 @@ var ( } c := make(chan v0.LegacyResponse) go common.Signald.Listen(c) - response := common.GetResponse(c, requestID) + response := signald.GetLegacyResponse(c, requestID) if response.Type == "verification_succeeded" { - log.Fatal("verification code requested. re-run with --verify") + log.Println("verification code requested. To submit it: signaldctl account verify -n", phoneNumber, " --code XXX-XXX") } else { log.Fatalf("unexpected response from signald when requesting verification code: %+v", response) } diff --git a/cmd/signaldctl/common/signald.go b/cmd/signaldctl/common/signald.go index 95773e1..3287838 100644 --- a/cmd/signaldctl/common/signald.go +++ b/cmd/signaldctl/common/signald.go @@ -4,7 +4,6 @@ import ( "log" "gitlab.com/signald/signald-go/signald" - "gitlab.com/signald/signald-go/signald/client-protocol/v0" ) var ( @@ -18,12 +17,3 @@ func Must(err error) { log.Fatal(err) } } - -func GetResponse(c chan v0.LegacyResponse, id string) v0.LegacyResponse { - for { - message := <-c - if message.ID == id { - return message - } - } -} diff --git a/signald/client-protocol/v0/signaldrequest.go b/signald/client-protocol/v0/signaldrequest.go index 8c841e9..dc58327 100644 --- a/signald/client-protocol/v0/signaldrequest.go +++ b/signald/client-protocol/v0/signaldrequest.go @@ -35,6 +35,6 @@ type LegacyRequest struct { } type JsonAddress struct { - Number string - UUID string + Number string `json:"number,omitempty" yaml:"number,omitempty"` + UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"` } diff --git a/signald/utils.go b/signald/utils.go index 58cea90..e60658d 100644 --- a/signald/utils.go +++ b/signald/utils.go @@ -2,6 +2,8 @@ package signald import ( "math/rand" + + "gitlab.com/signald/signald-go/signald/client-protocol/v0" ) const idsize = 10 @@ -16,3 +18,12 @@ func GenerateID() string { } return string(id) } + +func GetLegacyResponse(c chan v0.LegacyResponse, id string) v0.LegacyResponse { + for { + message := <-c + if message.ID == id { + return message + } + } +}