-
Notifications
You must be signed in to change notification settings - Fork 29
/
messages.go
52 lines (35 loc) · 1.52 KB
/
messages.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
package model
import (
"strconv"
"time"
"github.com/google/uuid"
"github.com/kdudkov/goatak/pkg/cot"
"github.com/kdudkov/goatak/pkg/cotproto"
)
const missionNotificationStale = time.Second * 5
func MissionChangeNotificationMsg(missionName string, scope string, c *Change) *cot.CotMessage {
msg := cot.BasicMsg("t-x-m-c", uuid.NewString(), missionNotificationStale)
msg.CotEvent.How = "h-g-i-g-o"
xd := cot.NewXMLDetails()
ch := xd.AddChild("mission", map[string]string{"type": "CHANGE", "name": missionName}, "").
AddChild("MissionChanges", nil, "").AddChild("MissionChange", nil, "")
ch.AddChild("contentUid", nil, c.ContentUID)
ch.AddChild("type", nil, c.Type)
ch.AddChild("isFederatedChange", nil, "false")
ch.AddChild("missionName", nil, missionName)
ch.AddChild("timestamp", nil, strconv.Itoa(int(c.CreateTime.Unix())))
msg.CotEvent.Detail = &cotproto.Detail{XmlDetail: xd.AsXMLString()}
return &cot.CotMessage{From: cot.LocalFrom, TakMessage: msg, Detail: xd, Scope: scope}
}
func MissionCreateNotificationMsg(m *Mission) *cot.CotMessage {
msg := cot.BasicMsg("t-x-m-n", uuid.NewString(), missionNotificationStale)
msg.CotEvent.How = "h-g-i-g-o"
xd := cot.NewXMLDetails()
params := map[string]string{"type": "CREATE", "name": m.Name, "creatorUid": m.CreatorUID}
if m.Tool != "" {
params["tool"] = m.Tool
}
xd.AddChild("mission", params, "")
msg.CotEvent.Detail = &cotproto.Detail{XmlDetail: xd.AsXMLString()}
return &cot.CotMessage{From: cot.LocalFrom, TakMessage: msg, Detail: xd, Scope: m.Scope}
}