rework title coloring

This commit is contained in:
Cubicroot 2021-05-02 18:11:14 +02:00
parent 2ff9f5972a
commit b0efac8b45
3 changed files with 12 additions and 19 deletions

View file

@ -58,5 +58,5 @@ crypto:
keylength: 32 keylength: 32
formatting: formatting:
# Whether to use colored titles based on the message priority. # Whether to use colored titles based on the message priority (<0: grey, 0-3: default, 4-10: yellow, 10-20: orange, >20: red).
coloredtitle: false coloredtitle: false

View file

@ -30,7 +30,6 @@ type NotificationHandler struct {
// CreateNotification is used to create a new notification for a user. // CreateNotification is used to create a new notification for a user.
func (h *NotificationHandler) CreateNotification(ctx *gin.Context) { func (h *NotificationHandler) CreateNotification(ctx *gin.Context) {
var notification model.Notification var notification model.Notification
notification.Priority = 8 // set a default value
if err := ctx.Bind(&notification); err != nil { if err := ctx.Bind(&notification); err != nil {
return return

View file

@ -46,7 +46,6 @@ func (d *Dispatcher) getFormattedMessage(n *model.Notification) string {
if optionsDisplayRaw, ok := n.Extras["client::display"]; ok { if optionsDisplayRaw, ok := n.Extras["client::display"]; ok {
optionsDisplay, ok := optionsDisplayRaw.(map[string]interface{}) optionsDisplay, ok := optionsDisplayRaw.(map[string]interface{})
log.Printf("%s", optionsDisplay)
if ok { if ok {
if contentTypeRaw, ok := optionsDisplay["contentType"]; ok { if contentTypeRaw, ok := optionsDisplay["contentType"]; ok {
@ -69,23 +68,18 @@ func (d *Dispatcher) getFormattedMessage(n *model.Notification) string {
// Maps priorities to hex colors // Maps priorities to hex colors
func (d *Dispatcher) priorityToColor(prio int) string { func (d *Dispatcher) priorityToColor(prio int) string {
switch prio { log.Printf("Prio: %d", prio)
case 0: // emergency - dark red switch {
return "#cc0000" case prio < 0:
case 1: // alert - red
return "#ed1f11"
case 2: // critical - dark orange
return "#ed6d11"
case 3: // error - orange
return "#edab11"
case 4: // warning - yellow
return "#edd711"
case 5: // notice - green
return "#70ed11"
case 6: // informational - blue
return "#118eed"
case 7: // debug - grey
return "#828282" return "#828282"
case prio <= 3: // info - default color
return ""
case prio <= 10: // low - yellow
return "#edd711"
case prio <= 20: // mid - orange
return "#ed6d11"
case prio > 20: // high - red
return "#ed1f11"
} }
return "" return ""