diff --git a/config/option.go b/config/option.go index e391768..759eac3 100644 --- a/config/option.go +++ b/config/option.go @@ -135,7 +135,7 @@ type QuickSetting struct { Action QuickSettingsAction } -// ValueRequirement defines a requirement on another configuraiton option. +// ValueRequirement defines a requirement on another configuration option. type ValueRequirement struct { // Key is the key of the configuration option that is required. Key string diff --git a/notifications/notification.go b/notifications/notification.go index 5b8a0ac..0c2a6be 100644 --- a/notifications/notification.go +++ b/notifications/notification.go @@ -152,13 +152,9 @@ func notify(nType Type, id, msg string, actions ...Action) *Notification { // Notify sends the given notification. func Notify(n *Notification) *Notification { - // Derive missing information. - if n.Message == "" { - n.Title = n.Message - } - if n.EventID == "" { - n.EventID = utils.DerivedInstanceUUID(n.Message).String() - } + // While this function is very similar to Save(), it is much nicer to use in + // order to just fire off one notification, as it does not require some more + // uncommon Go syntax. n.save(true) return n @@ -174,7 +170,7 @@ func (n *Notification) Save() { func (n *Notification) save(pushUpdate bool) { var id string - // Delete notification after processing deletion. + // Save notification after pre-save processing. defer func() { if id != "" { // Lock and save to notification storage. @@ -189,12 +185,26 @@ func (n *Notification) save(pushUpdate bool) { n.lock.Lock() defer n.lock.Unlock() + // Move Title to Message, as that is the required field. + if n.Message == "" { + n.Message = n.Title + n.Title = "" + } + // Check if required data is present. - if n.EventID == "" || n.Message == "" { - log.Warning("notifications: ignoring notification without EventID and Message") + if n.Message == "" { + log.Warning("notifications: ignoring notification without Message") return } + // Derive EventID from Message if not given. + if n.EventID == "" { + n.EventID = fmt.Sprintf( + "unknown:%s", + utils.DerivedInstanceUUID(n.Message).String(), + ) + } + // Save ID for deletion id = n.EventID