Make default ack action if notification has none

This commit is contained in:
Daniel 2020-05-22 15:07:30 +02:00
parent e83e2b216c
commit f2f1a56060
2 changed files with 13 additions and 18 deletions

View file

@ -54,7 +54,7 @@ func (lrw *LoggingResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
return nil, nil, errors.New("response does not implement http.Hijacker")
}
// RequestLogger is a logging middleware
// RequestLogger is a logging middleware.
func RequestLogger(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Tracef("api request: %s ___ %s", r.RemoteAddr, r.RequestURI)

View file

@ -123,6 +123,18 @@ func (n *Notification) Save() *Notification {
if n.GUID == "" {
n.GUID = uuid.NewV4().String()
}
// make ack notification if there are no defined actions
if len(n.AvailableActions) == 0 {
n.AvailableActions = []*Action{
{
ID: "ack",
Text: "OK",
},
}
n.actionFunction = noOpAction
}
// check key
if n.DatabaseKey() == "" {
n.SetKey(fmt.Sprintf("notifications:all/%s", n.ID))
@ -175,23 +187,6 @@ func (n *Notification) SetActionFunction(fn func(*Notification)) *Notification {
return n
}
// MakeAck sets a default "OK" action and a no-op action function.
func (n *Notification) MakeAck() *Notification {
n.lock.Lock()
defer n.lock.Unlock()
n.AvailableActions = []*Action{
{
ID: "ack",
Text: "OK",
},
}
n.Type = Info
n.actionFunction = noOpAction
return n
}
// Response waits for the user to respond to the notification and returns the selected action.
func (n *Notification) Response() <-chan string {
n.lock.Lock()