Add message react and message mark-read subcommands
This commit is contained in:
parent
2b94a65ca0
commit
d87a24bf2c
7 changed files with 383 additions and 78 deletions
142
cmd/signaldctl/cmd/message/react/react-to-message.go
Normal file
142
cmd/signaldctl/cmd/message/react/react-to-message.go
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
// Copyright © 2021 Finn Herzfeld <finn@janky.solutions>
|
||||||
|
//
|
||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package react
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/jedib0t/go-pretty/v6/table"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
|
||||||
|
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||||
|
"gitlab.com/signald/signald-go/cmd/signaldctl/config"
|
||||||
|
"gitlab.com/signald/signald-go/signald/client-protocol/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
account string
|
||||||
|
author string
|
||||||
|
timestamp int64
|
||||||
|
to string
|
||||||
|
remove bool
|
||||||
|
|
||||||
|
ReactMessageCmd = &cobra.Command{
|
||||||
|
Use: "react",
|
||||||
|
Short: "react to a message",
|
||||||
|
PreRun: func(_ *cobra.Command, args []string) {
|
||||||
|
if account == "" {
|
||||||
|
account = config.Config.DefaultAccount
|
||||||
|
}
|
||||||
|
if account == "" {
|
||||||
|
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||||
|
}
|
||||||
|
if len(args) != 1 {
|
||||||
|
log.Fatal("must provide exactly one reaction")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
|
go common.Signald.Listen(nil)
|
||||||
|
|
||||||
|
req := v1.ReactRequest{
|
||||||
|
Username: account,
|
||||||
|
Reaction: &v1.JsonReaction{
|
||||||
|
Emoji: args[0],
|
||||||
|
Remove: remove,
|
||||||
|
TargetAuthor: &v1.JsonAddress{Number: author},
|
||||||
|
TargetSentTimestamp: timestamp,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(to, "+") {
|
||||||
|
req.RecipientAddress = &v1.JsonAddress{Number: to}
|
||||||
|
} else {
|
||||||
|
req.RecipientGroupID = to
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := req.Submit(common.Signald)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("error sending request to signald: ", err)
|
||||||
|
}
|
||||||
|
switch common.OutputFormat {
|
||||||
|
case common.OutputFormatJSON:
|
||||||
|
err := json.NewEncoder(os.Stdout).Encode(resp)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err, "error encoding response to stdout")
|
||||||
|
}
|
||||||
|
case common.OutputFormatYAML:
|
||||||
|
err := yaml.NewEncoder(os.Stdout).Encode(resp)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err, "error encoding response to stdout")
|
||||||
|
}
|
||||||
|
case common.OutputFormatCSV, common.OutputFormatTable, common.OutputFormatDefault:
|
||||||
|
t := table.NewWriter()
|
||||||
|
t.SetOutputMirror(os.Stdout)
|
||||||
|
t.AppendHeader(table.Row{"Number", "UUID", "Duration", "Send Error"})
|
||||||
|
for _, result := range resp.Results {
|
||||||
|
if result.Success != nil {
|
||||||
|
t.AppendRow(table.Row{
|
||||||
|
result.Address.Number,
|
||||||
|
result.Address.UUID,
|
||||||
|
fmt.Sprintf("%dms", result.Success.Duration),
|
||||||
|
"",
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
var sendError string
|
||||||
|
if result.IdentityFailure != "" {
|
||||||
|
sendError = fmt.Sprintf("identity failure: %s\n", result.IdentityFailure)
|
||||||
|
}
|
||||||
|
if result.NetworkFailure {
|
||||||
|
sendError = "network failure"
|
||||||
|
}
|
||||||
|
if result.UnregisteredFailure {
|
||||||
|
sendError = "not on"
|
||||||
|
}
|
||||||
|
t.AppendRow(table.Row{result.Address.Number, result.Address.UUID, "", sendError})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if common.OutputFormat == common.OutputFormatCSV {
|
||||||
|
t.RenderCSV()
|
||||||
|
} else {
|
||||||
|
t.SetStyle(table.StyleLight)
|
||||||
|
t.Render()
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
log.Fatal("Unsupported output format")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
ReactMessageCmd.Flags().StringVarP(&account, "account", "a", "", "local account to use")
|
||||||
|
|
||||||
|
ReactMessageCmd.Flags().StringVarP(&to, "to", "t", "", "phone number or group ID that the message was sent to")
|
||||||
|
common.Must(ReactMessageCmd.MarkFlagRequired("to"))
|
||||||
|
|
||||||
|
ReactMessageCmd.Flags().Int64VarP(×tamp, "timestamp", "w", 0, "the timestamp of the message being reacted to")
|
||||||
|
common.Must(ReactMessageCmd.MarkFlagRequired("timestamp"))
|
||||||
|
|
||||||
|
ReactMessageCmd.Flags().StringVar(&author, "author", "", "the phone number of the author of the message being reacted to")
|
||||||
|
common.Must(ReactMessageCmd.MarkFlagRequired("author"))
|
||||||
|
|
||||||
|
ReactMessageCmd.Flags().BoolVarP(&remove, "remove", "r", false, "remove a reaction that was previously set")
|
||||||
|
}
|
75
cmd/signaldctl/cmd/message/read/mark-message-as-read.go
Normal file
75
cmd/signaldctl/cmd/message/read/mark-message-as-read.go
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
// Copyright © 2021 Finn Herzfeld <finn@janky.solutions>
|
||||||
|
//
|
||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package read
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||||
|
"gitlab.com/signald/signald-go/cmd/signaldctl/config"
|
||||||
|
"gitlab.com/signald/signald-go/signald/client-protocol/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
account string
|
||||||
|
to string
|
||||||
|
|
||||||
|
ReadMessageCmd = &cobra.Command{
|
||||||
|
Use: "mark-read",
|
||||||
|
Short: "mark a message as read",
|
||||||
|
PreRun: func(_ *cobra.Command, args []string) {
|
||||||
|
if account == "" {
|
||||||
|
account = config.Config.DefaultAccount
|
||||||
|
}
|
||||||
|
if account == "" {
|
||||||
|
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||||
|
}
|
||||||
|
if len(args) < 2 {
|
||||||
|
log.Fatal("Usage: signaldctl message mark-read <author> <timestamp>")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
|
go common.Signald.Listen(nil)
|
||||||
|
|
||||||
|
timestamps := []int64{}
|
||||||
|
for _, arg := range args[1:] {
|
||||||
|
ts, err := strconv.ParseInt(arg, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("unable to parse timestamp: ", arg)
|
||||||
|
}
|
||||||
|
timestamps = append(timestamps, ts)
|
||||||
|
}
|
||||||
|
|
||||||
|
req := v1.MarkReadRequest{
|
||||||
|
Account: account,
|
||||||
|
Timestamps: timestamps,
|
||||||
|
To: &v1.JsonAddress{Number: args[0]},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := req.Submit(common.Signald)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("error sending request to signald: ", err)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
ReadMessageCmd.Flags().StringVarP(&account, "account", "a", "", "local account to use")
|
||||||
|
}
|
|
@ -18,6 +18,8 @@ package message
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/message/react"
|
||||||
|
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/message/read"
|
||||||
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/message/send"
|
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/message/send"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,4 +30,6 @@ var MessageCmd = &cobra.Command{
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
MessageCmd.AddCommand(send.SendMessageCmd)
|
MessageCmd.AddCommand(send.SendMessageCmd)
|
||||||
|
MessageCmd.AddCommand(react.ReactMessageCmd)
|
||||||
|
MessageCmd.AddCommand(read.ReadMessageCmd)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,10 @@ func (r *AcceptInvitationRequest) Submit(conn *signald.Signald) (response JsonGr
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -32,11 +31,12 @@ func (r *AcceptInvitationRequest) Submit(conn *signald.Signald) (response JsonGr
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -50,11 +50,10 @@ func (r *ApproveMembershipRequest) Submit(conn *signald.Signald) (response JsonG
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -65,11 +64,12 @@ func (r *ApproveMembershipRequest) Submit(conn *signald.Signald) (response JsonG
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -83,11 +83,10 @@ func (r *GetGroupRequest) Submit(conn *signald.Signald) (response JsonGroupV2Inf
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -98,11 +97,12 @@ func (r *GetGroupRequest) Submit(conn *signald.Signald) (response JsonGroupV2Inf
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -116,11 +116,10 @@ func (r *GetLinkedDevicesRequest) Submit(conn *signald.Signald) (response Linked
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -131,11 +130,12 @@ func (r *GetLinkedDevicesRequest) Submit(conn *signald.Signald) (response Linked
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -149,11 +149,10 @@ func (r *GetProfileRequest) Submit(conn *signald.Signald) (response Profile, err
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -164,11 +163,12 @@ func (r *GetProfileRequest) Submit(conn *signald.Signald) (response Profile, err
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -182,11 +182,10 @@ func (r *JoinGroupRequest) Submit(conn *signald.Signald) (response JsonGroupJoin
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -197,11 +196,12 @@ func (r *JoinGroupRequest) Submit(conn *signald.Signald) (response JsonGroupJoin
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -214,11 +214,10 @@ func (r *ListContactsRequest) Submit(conn *signald.Signald) (response ProfileLis
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -229,11 +228,12 @@ func (r *ListContactsRequest) Submit(conn *signald.Signald) (response ProfileLis
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -246,11 +246,10 @@ func (r *ListGroupsRequest) Submit(conn *signald.Signald) (response GroupList, e
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -261,36 +260,65 @@ func (r *ListGroupsRequest) Submit(conn *signald.Signald) (response GroupList, e
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *MarkReadRequest) Submit(conn *signald.Signald) error {
|
func (r *MarkReadRequest) Submit(conn *signald.Signald) (err error) {
|
||||||
r.Version = "v1"
|
r.Version = "v1"
|
||||||
r.Type = "mark_read"
|
r.Type = "mark_read"
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
err = conn.RawRequest(r)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("signald-go: error submitting request to signald")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
return conn.RawRequest(r)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
defer conn.CloseResponseListener(r.ID)
|
||||||
|
|
||||||
|
rawResponse := <-responseChannel
|
||||||
|
if rawResponse.Error != nil {
|
||||||
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ProtocolRequest) Submit(conn *signald.Signald) error {
|
func (r *ProtocolRequest) Submit(conn *signald.Signald) (err error) {
|
||||||
r.Version = "v1"
|
r.Version = "v1"
|
||||||
r.Type = "protocol"
|
r.Type = "protocol"
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
err = conn.RawRequest(r)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("signald-go: error submitting request to signald")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
return conn.RawRequest(r)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
defer conn.CloseResponseListener(r.ID)
|
||||||
|
|
||||||
|
rawResponse := <-responseChannel
|
||||||
|
if rawResponse.Error != nil {
|
||||||
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,11 +329,10 @@ func (r *ReactRequest) Submit(conn *signald.Signald) (response SendResponse, err
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -316,11 +343,12 @@ func (r *ReactRequest) Submit(conn *signald.Signald) (response SendResponse, err
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -328,14 +356,28 @@ func (r *ReactRequest) Submit(conn *signald.Signald) (response SendResponse, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submit: Remove a linked device from the Signal account. Only allowed when the local device id is 1
|
// Submit: Remove a linked device from the Signal account. Only allowed when the local device id is 1
|
||||||
func (r *RemoveLinkedDeviceRequest) Submit(conn *signald.Signald) error {
|
func (r *RemoveLinkedDeviceRequest) Submit(conn *signald.Signald) (err error) {
|
||||||
r.Version = "v1"
|
r.Version = "v1"
|
||||||
r.Type = "remove_linked_device"
|
r.Type = "remove_linked_device"
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
err = conn.RawRequest(r)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("signald-go: error submitting request to signald")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
return conn.RawRequest(r)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
defer conn.CloseResponseListener(r.ID)
|
||||||
|
|
||||||
|
rawResponse := <-responseChannel
|
||||||
|
if rawResponse.Error != nil {
|
||||||
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,11 +388,10 @@ func (r *ResolveAddressRequest) Submit(conn *signald.Signald) (response JsonAddr
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -361,11 +402,12 @@ func (r *ResolveAddressRequest) Submit(conn *signald.Signald) (response JsonAddr
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -378,11 +420,10 @@ func (r *SendRequest) Submit(conn *signald.Signald) (response SendResponse, err
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -393,25 +434,40 @@ func (r *SendRequest) Submit(conn *signald.Signald) (response SendResponse, err
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *SetProfile) Submit(conn *signald.Signald) error {
|
func (r *SetProfile) Submit(conn *signald.Signald) (err error) {
|
||||||
r.Version = "v1"
|
r.Version = "v1"
|
||||||
r.Type = "set_profile"
|
r.Type = "set_profile"
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
err = conn.RawRequest(r)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("signald-go: error submitting request to signald")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
return conn.RawRequest(r)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
defer conn.CloseResponseListener(r.ID)
|
||||||
|
|
||||||
|
rawResponse := <-responseChannel
|
||||||
|
if rawResponse.Error != nil {
|
||||||
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,11 +478,10 @@ func (r *UpdateGroupRequest) Submit(conn *signald.Signald) (response GroupInfo,
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -437,11 +492,12 @@ func (r *UpdateGroupRequest) Submit(conn *signald.Signald) (response GroupInfo,
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -454,11 +510,10 @@ func (r *VersionRequest) Submit(conn *signald.Signald) (response JsonVersionMess
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -469,11 +524,12 @@ func (r *VersionRequest) Submit(conn *signald.Signald) (response JsonVersionMess
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
|
|
@ -17,11 +17,10 @@ func (r *AcceptInvitationRequest) Submit(conn *signald.Signald) (response JsonGr
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -32,11 +31,12 @@ func (r *AcceptInvitationRequest) Submit(conn *signald.Signald) (response JsonGr
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -50,11 +50,10 @@ func (r *ApproveMembershipRequest) Submit(conn *signald.Signald) (response JsonG
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -65,11 +64,12 @@ func (r *ApproveMembershipRequest) Submit(conn *signald.Signald) (response JsonG
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -83,11 +83,10 @@ func (r *GetGroupRequest) Submit(conn *signald.Signald) (response JsonGroupV2Inf
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -98,11 +97,12 @@ func (r *GetGroupRequest) Submit(conn *signald.Signald) (response JsonGroupV2Inf
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -116,11 +116,10 @@ func (r *GetLinkedDevicesRequest) Submit(conn *signald.Signald) (response Linked
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -131,11 +130,12 @@ func (r *GetLinkedDevicesRequest) Submit(conn *signald.Signald) (response Linked
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -149,11 +149,10 @@ func (r *JoinGroupRequest) Submit(conn *signald.Signald) (response JsonGroupJoin
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -164,37 +163,66 @@ func (r *JoinGroupRequest) Submit(conn *signald.Signald) (response JsonGroupJoin
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ProtocolRequest) Submit(conn *signald.Signald) error {
|
func (r *ProtocolRequest) Submit(conn *signald.Signald) (err error) {
|
||||||
r.Version = "v1alpha1"
|
r.Version = "v1alpha1"
|
||||||
r.Type = "protocol"
|
r.Type = "protocol"
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
err = conn.RawRequest(r)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("signald-go: error submitting request to signald")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
return conn.RawRequest(r)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
defer conn.CloseResponseListener(r.ID)
|
||||||
|
|
||||||
|
rawResponse := <-responseChannel
|
||||||
|
if rawResponse.Error != nil {
|
||||||
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submit: Remove a linked device from the Signal account. Only allowed when the local device id is 1
|
// Submit: Remove a linked device from the Signal account. Only allowed when the local device id is 1
|
||||||
func (r *RemoveLinkedDeviceRequest) Submit(conn *signald.Signald) error {
|
func (r *RemoveLinkedDeviceRequest) Submit(conn *signald.Signald) (err error) {
|
||||||
r.Version = "v1alpha1"
|
r.Version = "v1alpha1"
|
||||||
r.Type = "remove_linked_device"
|
r.Type = "remove_linked_device"
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
err = conn.RawRequest(r)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("signald-go: error submitting request to signald")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
return conn.RawRequest(r)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
defer conn.CloseResponseListener(r.ID)
|
||||||
|
|
||||||
|
rawResponse := <-responseChannel
|
||||||
|
if rawResponse.Error != nil {
|
||||||
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,11 +233,10 @@ func (r *UpdateGroupRequest) Submit(conn *signald.Signald) (response JsonGroupV2
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -220,11 +247,12 @@ func (r *UpdateGroupRequest) Submit(conn *signald.Signald) (response JsonGroupV2
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
|
|
@ -17,11 +17,10 @@ func (r *UpdateGroupRequest) Submit(conn *signald.Signald) (response GroupInfo,
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -32,11 +31,12 @@ func (r *UpdateGroupRequest) Submit(conn *signald.Signald) (response GroupInfo,
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
|
|
@ -13,7 +13,7 @@ import ({{if .Responses}}
|
||||||
{{range $type, $action := .Actions}}
|
{{range $type, $action := .Actions}}
|
||||||
{{if ne $action.Request ""}}
|
{{if ne $action.Request ""}}
|
||||||
{{if ne $action.Doc ""}}// Submit: {{$action.Doc}}{{end}}
|
{{if ne $action.Doc ""}}// Submit: {{$action.Doc}}{{end}}
|
||||||
func (r *{{$action.Request}}) Submit(conn *signald.Signald) ({{if ne $action.Response ""}}response {{$action.Response}}, err {{end}}error) {
|
func (r *{{$action.Request}}) Submit(conn *signald.Signald) ({{if ne $action.Response ""}}response {{$action.Response}}, {{end}}err error) {
|
||||||
r.Version = "{{$.Version}}"
|
r.Version = "{{$.Version}}"
|
||||||
{{else}}
|
{{else}}
|
||||||
{{if ne $action.Doc ""}}// {{$action.FnName}}: {{$action.Doc}}{{end}}
|
{{if ne $action.Doc ""}}// {{$action.FnName}}: {{$action.Doc}}{{end}}
|
||||||
|
@ -23,12 +23,10 @@ func {{$action.FnName}}(conn *signald.Signald) ({{if ne $action.Response ""}}res
|
||||||
if(r.ID == "") {
|
if(r.ID == "") {
|
||||||
r.ID = signald.GenerateID()
|
r.ID = signald.GenerateID()
|
||||||
}
|
}
|
||||||
|
|
||||||
{{if ne $action.Response ""}}
|
|
||||||
err = conn.RawRequest(r)
|
err = conn.RawRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("signald-go: error submitting request to signald")
|
log.Println("signald-go: error submitting request to signald")
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responseChannel := conn.GetResponseListener(r.ID)
|
responseChannel := conn.GetResponseListener(r.ID)
|
||||||
|
@ -39,16 +37,18 @@ func {{$action.FnName}}(conn *signald.Signald) ({{if ne $action.Response ""}}res
|
||||||
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
err = fmt.Errorf("signald error: %s", string(rawResponse.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{{if ne $action.Response ""}}
|
||||||
err = json.Unmarshal(rawResponse.Data, &response)
|
err = json.Unmarshal(rawResponse.Data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
rawResponseJson, _ := rawResponse.Data.MarshalJSON()
|
||||||
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson))
|
||||||
return response, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
{{else}}
|
{{else}}
|
||||||
return conn.RawRequest(r)
|
return err
|
||||||
{{end}}
|
{{end}}
|
||||||
}
|
}
|
||||||
{{end}}
|
{{end}}
|
Loading…
Reference in a new issue