Update some structures
This commit is contained in:
parent
352c423dd4
commit
34a208588b
3 changed files with 64 additions and 25 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,18 +38,28 @@ class JsonRequest {
|
||||||
|
|
||||||
// Request represents a message sent to signald
|
// Request represents a message sent to signald
|
||||||
type Request struct {
|
type Request struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
Username string `json:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
MessageBody string `json:"messageBody,omitempty"`
|
MessageBody string `json:"messageBody,omitempty"`
|
||||||
RecipientNumber string `json:"recipientNumber,omitempty"`
|
RecipientNumber string `json:"recipientNumber,omitempty"`
|
||||||
RecipientGroupID string `json:"recipientGroupId,omitempty"`
|
RecipientGroupID string `json:"recipientGroupId,omitempty"`
|
||||||
Voice bool `json:"voice,omitempty"`
|
Voice bool `json:"voice,omitempty"`
|
||||||
Code string `json:"code,omitempty"`
|
Code string `json:"code,omitempty"`
|
||||||
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"`
|
||||||
GroupName string `json:"groupName,omitempty"`
|
Attachments []Attachment `json:"attachments,omitempty"`
|
||||||
Members []string `json:"members,omitempty"`
|
GroupName string `json:"groupName,omitempty"`
|
||||||
Avatar string `json:"avatar,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"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,18 @@ type Response struct {
|
||||||
|
|
||||||
// ResponseData is where most of the data in the response is stored.
|
// ResponseData is where most of the data in the response is stored.
|
||||||
type ResponseData struct {
|
type ResponseData struct {
|
||||||
Groups []Group
|
Groups []Group
|
||||||
Accounts []Account
|
Accounts []Account
|
||||||
URI string
|
URI string
|
||||||
Message 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
|
// 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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue