diff --git a/cmd/signald-cli/cmd/listAccounts.go b/cmd/signald-cli/cmd/listAccounts.go new file mode 100644 index 0000000..e856e15 --- /dev/null +++ b/cmd/signald-cli/cmd/listAccounts.go @@ -0,0 +1,55 @@ +// Copyright © 2018 Finn Herzfeld +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package cmd + +import ( + "fmt" + "math/rand" + + "github.com/spf13/cobra" + + "git.callpipe.com/finn/signald-go/signald" +) + +// listAccountsCmd represents the listAccounts command +var listAccountsCmd = &cobra.Command{ + Use: "listAccounts", + Short: "list of all the accounts registered to this signald instance.", + Long: `Prints a list of all users to stdout.`, + Run: func(cmd *cobra.Command, args []string) { + requestID := fmt.Sprint("signald-cli-", rand.Intn(1000)) + s.SendRequest(signald.Request{ + Type: "list_accounts", + ID: requestID, + }) + + c := make(chan signald.Response) + go s.Listen(c) + for { + message := <-c + if message.ID == requestID { + for _, account := range message.Data.Accounts { + fmt.Println(account.Username) + } + break + } + } + }, +} + +func init() { + RootCmd.AddCommand(listAccountsCmd) +} diff --git a/signald/signaldresponse.go b/signald/signaldresponse.go index 3f319d4..1625918 100644 --- a/signald/signaldresponse.go +++ b/signald/signaldresponse.go @@ -9,9 +9,10 @@ type Response struct { // ResponseData is where most of the data in the response is stored. type ResponseData struct { - Groups []Group - URI string - Message string + Groups []Group + Accounts []Account + URI string + Message string } // Group represents a group in signal @@ -21,3 +22,13 @@ type Group struct { Name string AvatarID int } + +// Account represents a user account registered to signald +type Account struct { + Username string + DeviceID int + Filename string + Registered bool + HasKeys bool `json:"has_keys"` + Subscribed bool +}