adopt to review

change formatting options to separate struct and clean up
This commit is contained in:
Cubicroot 2021-05-02 15:37:54 +02:00
parent fe1cbdf79e
commit 2ff9f5972a
6 changed files with 22 additions and 20 deletions

View file

@ -18,6 +18,11 @@ type CryptoConfig struct {
Argon2 Argon2Config
}
// Formatting holds additional parameters used for formatting messages
type Formatting struct {
ColoredTitle bool `default:"false"`
}
// Configuration holds values that can be configured by the user.
type Configuration struct {
Debug bool `default:"false"`
@ -42,8 +47,8 @@ type Configuration struct {
Security struct {
CheckHIBP bool `default:"false"`
}
Crypto CryptoConfig
Message map[string]interface{}
Crypto CryptoConfig
Formatting Formatting
}
func configFiles() []string {

View file

@ -4,6 +4,7 @@ import (
"log"
"github.com/matrix-org/gomatrix"
"github.com/pushbits/server/internal/configuration"
)
var (
@ -16,13 +17,13 @@ type Database interface {
// Dispatcher holds information for sending notifications to clients.
type Dispatcher struct {
db Database
client *gomatrix.Client
settings map[string]interface{}
db Database
client *gomatrix.Client
formatting configuration.Formatting
}
// Create instanciates a dispatcher connection.
func Create(db Database, homeserver, username, password string, settings map[string]interface{}) (*Dispatcher, error) {
func Create(db Database, homeserver, username, password string, formatting configuration.Formatting) (*Dispatcher, error) {
log.Println("Setting up dispatcher.")
client, err := gomatrix.NewClient(homeserver, "", "")
@ -41,7 +42,7 @@ func Create(db Database, homeserver, username, password string, settings map[str
client.SetCredentials(response.UserID, response.AccessToken)
return &Dispatcher{client: client, settings: settings}, nil
return &Dispatcher{client: client, formatting: formatting}, nil
}
// Close closes the dispatcher connection.

View file

@ -32,12 +32,8 @@ func (d *Dispatcher) getFormattedTitle(n *model.Notification) string {
trimmedTitle := strings.TrimSpace(n.Title)
title := html.EscapeString(trimmedTitle)
if valueRaw, ok := d.settings["coloredtitle"]; ok {
value, ok := valueRaw.(bool)
if ok && value {
title = d.coloredText(d.priorityToColor(n.Priority), title)
}
if d.formatting.ColoredTitle {
title = d.coloredText(d.priorityToColor(n.Priority), title)
}
return "<b>" + title + "</b><br /><br />"