Sorting > 1 and docs

This commit is contained in:
Steven Wolfe 2019-01-09 10:35:50 -07:00
parent a5fbcf5f15
commit eb2ff76f86
1 changed files with 11 additions and 5 deletions

View File

@ -260,8 +260,12 @@ func (server *Server) queueHooks(d *commandDetails) error {
} }
// Sort both message channel and webhook message slices // Sort both message channel and webhook message slices
sortMsgs(cmsgs) if len(cmsgs) > 1 {
sortMsgs(wmsgs) sortMsgs(cmsgs)
}
if len(wmsgs) > 1 {
sortMsgs(wmsgs)
}
// Publish all channel messages if any exist // Publish all channel messages if any exist
if len(cmsgs) > 0 { if len(cmsgs) > 0 {
@ -298,8 +302,9 @@ func (server *Server) queueHooks(d *commandDetails) error {
return nil return nil
} }
// sortMsgs sorts passed notification messages by their detect and hook fields
func sortMsgs(msgs []string) { func sortMsgs(msgs []string) {
sort.Slice(msgs, func(i, j int) bool { sort.SliceStable(msgs, func(i, j int) bool {
detectI := msgDetectCode(gjson.Get(msgs[i], "detect").String()) detectI := msgDetectCode(gjson.Get(msgs[i], "detect").String())
detectJ := msgDetectCode(gjson.Get(msgs[j], "detect").String()) detectJ := msgDetectCode(gjson.Get(msgs[j], "detect").String())
if detectI < detectJ { if detectI < detectJ {
@ -314,8 +319,9 @@ func sortMsgs(msgs []string) {
}) })
} }
func msgDetectCode(msg string) int { // msgDetectCode returns a weight value for the passed detect value
switch msg { func msgDetectCode(detect string) int {
switch detect {
case "exit": case "exit":
return 1 return 1
case "outside": case "outside":