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
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -49,7 +49,17 @@ type Request struct {
|
|||
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"`
|
||||
}
|
||||
|
|
|
@ -12,7 +12,15 @@ type ResponseData struct {
|
|||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue