diff --git a/signald/signald.go b/signald/signald.go index f1b8144..6e97b11 100644 --- a/signald/signald.go +++ b/signald/signald.go @@ -34,34 +34,41 @@ func crash(err error) { } // Connect connects to the signad socket -func (s *Signald) Connect() { +func (s *Signald) Connect() error { if s.SocketPath == "" { s.SocketPath = "/var/run/signald/signald.sock" } socket, err := net.Dial("unix", s.SocketPath) - crash(err) + if err != nil { + return err + } s.socket = socket log.Print("Connected to signald socket ", socket.RemoteAddr().String()) + return nil } // Listen listens for events from signald -func (s *Signald) Listen(c chan Response) { +func (s *Signald) Listen(c chan Response) error { // we create a decoder that reads directly from the socket d := json.NewDecoder(s.socket) var msg Response for { - crash(d.Decode(&msg)) + if err := d.Decode(&msg); err != nil { + return err + } c <- msg } } // SendRequest sends a request to signald. Mostly used interally. -func (s *Signald) SendRequest(request Request) { +func (s *Signald) SendRequest(request Request) error { b, err := json.Marshal(request) - crash(err) + if err != nil { + return err + } log.Print("Sending ", string(b)) e := json.NewEncoder(s.socket) - e.Encode(request) + return e.Encode(request) } diff --git a/signald/signaldrequest.go b/signald/signaldrequest.go index 9e54eb2..fb622bd 100644 --- a/signald/signaldrequest.go +++ b/signald/signaldrequest.go @@ -38,18 +38,28 @@ class JsonRequest { // Request represents a message sent to signald type Request struct { - Type string `json:"type"` - ID string `json:"id,omitempty"` - Username string `json:"username,omitempty"` - MessageBody string `json:"messageBody,omitempty"` - RecipientNumber string `json:"recipientNumber,omitempty"` - RecipientGroupID string `json:"recipientGroupId,omitempty"` - Voice bool `json:"voice,omitempty"` - Code string `json:"code,omitempty"` - DeviceName string `json:"deviceName,omitempty"` - AttachmentFilenames []string `json:"attachmentFilenames,omitempty"` - URI string `json:"uri,omitempty"` - GroupName string `json:"groupName,omitempty"` - Members []string `json:"members,omitempty"` - Avatar string `json:"avatar,omitempty"` + Type string `json:"type"` + ID string `json:"id,omitempty"` + Username string `json:"username,omitempty"` + MessageBody string `json:"messageBody,omitempty"` + RecipientNumber string `json:"recipientNumber,omitempty"` + RecipientGroupID string `json:"recipientGroupId,omitempty"` + Voice bool `json:"voice,omitempty"` + Code string `json:"code,omitempty"` + DeviceName string `json:"deviceName,omitempty"` + AttachmentFilenames []string `json:"attachmentFilenames,omitempty"` + URI string `json:"uri,omitempty"` + Attachments []Attachment `json:"attachments,omitempty"` + GroupName string `json:"groupName,omitempty"` + Members []string `json:"members,omitempty"` + Avatar string `json:"avatar,omitempty"` +} + +type Attachment struct { + Filename string `json:"filename"` + Caption string `json:"caption"` + Width int `json:"width"` + Height int `json:"height"` + VoiceNote bool `json:"voiceNote"` + Preview bool `json:"preview"` } diff --git a/signald/signaldresponse.go b/signald/signaldresponse.go index 1625918..22b23e1 100644 --- a/signald/signaldresponse.go +++ b/signald/signaldresponse.go @@ -9,10 +9,18 @@ type Response struct { // ResponseData is where most of the data in the response is stored. type ResponseData struct { - Groups []Group - Accounts []Account - URI string - Message string + Groups []Group + Accounts []Account + URI string + DataMessage DataMessage + Message string + Username string + Source string + SourceDevice int + Type int + IsReceipt bool + Timestamp float64 + ServerTimestamp float64 } // Group represents a group in signal @@ -32,3 +40,17 @@ type Account struct { HasKeys bool `json:"has_keys"` Subscribed bool } + +// DataMessage is the main component of incoming text messages +type DataMessage struct { + Timestamp float64 + Message string + ExpiresInSeconds float64 + GroupInfo IncomingGroupInfo +} + +// IncomingGroupInfo is information about a particular group +type IncomingGroupInfo struct { + GroupID string + Type string +}