-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpush.go
87 lines (75 loc) · 1.83 KB
/
push.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"encoding/json"
"io"
"os"
"time"
log "github.com/Sirupsen/logrus"
"github.com/gosexy/gettext"
)
// run as the application push helper
func pushHelperProcess() {
in, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
out, err := os.Create(os.Args[2])
if err != nil {
log.Fatal(err)
}
err = pushHelperProcessMessage(in, out)
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}
type pushMessage struct {
Notification string `json:"notification"`
}
type appMessageCard struct {
Summary string `json:"summary"`
Body string `json:"body"`
Actions []string `json:"actions"`
Popup bool `json:"popup"`
Persist bool `json:"persist"`
Timestamp int64 `json:"timestamp"`
}
type appMessageEmblemCounter struct {
Count int `json:"count"`
Visible bool `json:"visible"`
}
type appMessageNotification struct {
Tag string `json:"tag"`
Card appMessageCard `json:"card"`
Sound bool `json:"sound"`
Vibrate bool `json:"vibrate"`
EmblemCounter appMessageEmblemCounter `json:"emblem-counter"`
}
type appMessage struct {
Notification appMessageNotification `json:"notification"`
}
func pushHelperProcessMessage(in io.Reader, out io.Writer) error {
pushMsg := &pushMessage{}
dec := json.NewDecoder(in)
err := dec.Decode(pushMsg)
if err != nil {
return err
}
appMsg := &appMessage{
Notification: appMessageNotification{
Card: appMessageCard{
Summary: gettext.Gettext("New message"),
Body: "",
Actions: []string{"appid://textsecure.jani/textsecure/current-user-version"},
Popup: true,
Persist: true,
Timestamp: time.Now().Unix(),
},
Sound: true,
Vibrate: true,
},
}
enc := json.NewEncoder(out)
err = enc.Encode(appMsg)
return err
}