mirror of
https://github.com/pushbits/server.git
synced 2025-05-01 19:26:41 +02:00
adopt to review
change formatting options to separate struct and clean up
This commit is contained in:
parent
fe1cbdf79e
commit
2ff9f5972a
6 changed files with 22 additions and 20 deletions
|
@ -116,19 +116,19 @@ pbcli application show $PB_APPLICATION --url https://pushbits.example.com --user
|
|||
|
||||
### Message options
|
||||
|
||||
Messages are supporting thre different syntaxes:
|
||||
Messages are supporting three different syntaxes:
|
||||
|
||||
* text/plain
|
||||
* text/html
|
||||
* text/markdown
|
||||
|
||||
To set a specific syntax you need to set the `extras`:
|
||||
To set a specific syntax you need to set the `extras` ([inspired by Gotifys message extras](https://gotify.net/docs/msgextras#clientdisplay)):
|
||||
|
||||
```bash
|
||||
curl \
|
||||
--header "Content-Type: application/json" \
|
||||
--request POST \
|
||||
--data '{"message":"my message with\n\n**Markdown** _support_.","title":"my title","extras":{"client::display":{"contentType": "text/html"}}}' \
|
||||
--data '{"message":"my message with\n\n**Markdown** _support_.","title":"my title","extras":{"client::display":{"contentType": "text/markdown"}}}' \
|
||||
"https://pushbits.example.com/message?token=$PB_TOKEN"
|
||||
```
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
dp, err := dispatcher.Create(db, c.Matrix.Homeserver, c.Matrix.Username, c.Matrix.Password, c.Message)
|
||||
dp, err := dispatcher.Create(db, c.Matrix.Homeserver, c.Matrix.Username, c.Matrix.Password, c.Formatting)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -57,6 +57,6 @@ crypto:
|
|||
saltlength: 16
|
||||
keylength: 32
|
||||
|
||||
message:
|
||||
# add coloring to the title according to syslog priorities
|
||||
# coloredtitle: true
|
||||
formatting:
|
||||
# Whether to use colored titles based on the message priority.
|
||||
coloredtitle: false
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 />"
|
||||
|
|
Loading…
Add table
Reference in a new issue