Update some structures

This commit is contained in:
Finn 2020-06-25 02:42:33 -07:00
parent 352c423dd4
commit 34a208588b
3 changed files with 64 additions and 25 deletions

View file

@ -34,34 +34,41 @@ func crash(err error) {
} }
// Connect connects to the signad socket // Connect connects to the signad socket
func (s *Signald) Connect() { func (s *Signald) Connect() error {
if s.SocketPath == "" { if s.SocketPath == "" {
s.SocketPath = "/var/run/signald/signald.sock" s.SocketPath = "/var/run/signald/signald.sock"
} }
socket, err := net.Dial("unix", s.SocketPath) socket, err := net.Dial("unix", s.SocketPath)
crash(err) if err != nil {
return err
}
s.socket = socket s.socket = socket
log.Print("Connected to signald socket ", socket.RemoteAddr().String()) log.Print("Connected to signald socket ", socket.RemoteAddr().String())
return nil
} }
// Listen listens for events from signald // 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 // we create a decoder that reads directly from the socket
d := json.NewDecoder(s.socket) d := json.NewDecoder(s.socket)
var msg Response var msg Response
for { for {
crash(d.Decode(&msg)) if err := d.Decode(&msg); err != nil {
return err
}
c <- msg c <- msg
} }
} }
// SendRequest sends a request to signald. Mostly used interally. // 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) b, err := json.Marshal(request)
crash(err) if err != nil {
return err
}
log.Print("Sending ", string(b)) log.Print("Sending ", string(b))
e := json.NewEncoder(s.socket) e := json.NewEncoder(s.socket)
e.Encode(request) return e.Encode(request)
} }

View file

@ -49,7 +49,17 @@ type Request struct {
DeviceName string `json:"deviceName,omitempty"` DeviceName string `json:"deviceName,omitempty"`
AttachmentFilenames []string `json:"attachmentFilenames,omitempty"` AttachmentFilenames []string `json:"attachmentFilenames,omitempty"`
URI string `json:"uri,omitempty"` URI string `json:"uri,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
GroupName string `json:"groupName,omitempty"` GroupName string `json:"groupName,omitempty"`
Members []string `json:"members,omitempty"` Members []string `json:"members,omitempty"`
Avatar string `json:"avatar,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"`
}

View file

@ -12,7 +12,15 @@ type ResponseData struct {
Groups []Group Groups []Group
Accounts []Account Accounts []Account
URI string URI string
DataMessage DataMessage
Message string Message string
Username string
Source string
SourceDevice int
Type int
IsReceipt bool
Timestamp float64
ServerTimestamp float64
} }
// Group represents a group in signal // Group represents a group in signal
@ -32,3 +40,17 @@ type Account struct {
HasKeys bool `json:"has_keys"` HasKeys bool `json:"has_keys"`
Subscribed bool 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
}