Assorted refactor

This commit is contained in:
Finn 2021-02-01 17:37:48 -08:00
parent 70c1cb5ea2
commit 3cf02aebb0
7 changed files with 21 additions and 18 deletions

View file

@ -31,4 +31,6 @@ signaldctl account create --verify --phone-number +15555555555 --code 999-999
```
signaldctl message send --account +15555555555 --to +12024561414 --message "yo"
```
```
`--to` can also be a group ID

View file

@ -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

View file

@ -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 {

View file

@ -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)
}

View file

@ -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
}
}
}

View file

@ -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"`
}

View file

@ -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
}
}
}