mirror of
https://github.com/pushbits/server.git
synced 2025-08-01 23:59:06 +02:00
added formatting options
This commit is contained in:
parent
2e2326843f
commit
567c814968
4 changed files with 34 additions and 2 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/pushbits/server/internal/model"
|
||||
)
|
||||
|
||||
|
@ -16,10 +17,36 @@ func (d *Dispatcher) SendNotification(a *model.Application, n *model.Notificatio
|
|||
plainTitle := strings.TrimSpace(n.Title)
|
||||
plainMessage := strings.TrimSpace(n.Message)
|
||||
escapedTitle := html.EscapeString(plainTitle)
|
||||
escapedMessage := html.EscapeString(plainMessage)
|
||||
message := html.EscapeString(plainMessage) // default to text/plain
|
||||
|
||||
if optionsDisplayRaw, ok := n.Extras["client::display"]; ok {
|
||||
optionsDisplay, ok := optionsDisplayRaw.(map[string]interface{})
|
||||
log.Printf("%s", optionsDisplay)
|
||||
|
||||
if ok {
|
||||
if contentTypeRaw, ok := optionsDisplay["contentType"]; ok {
|
||||
contentType := fmt.Sprintf("%v", contentTypeRaw)
|
||||
log.Printf("Message content type: %s", contentType)
|
||||
|
||||
switch contentType {
|
||||
case "html", "text/html":
|
||||
message = plainMessage
|
||||
case "markdown", "md", "text/md", "text/markdown":
|
||||
message = string(markdown.ToHTML([]byte(plainMessage), nil, nil))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO cubicroot: add colors for priority https://spec.matrix.org/unstable/client-server-api/#mroommessage-msgtypes
|
||||
// maybe make this optional in the settings or so
|
||||
|
||||
// TODO cubicroot: check if we somehow can handle \n or other methods of line breaks
|
||||
|
||||
// TODO cubicroot: add docu
|
||||
|
||||
text := fmt.Sprintf("%s\n\n%s", plainTitle, plainMessage)
|
||||
formattedText := fmt.Sprintf("<b>%s</b><br /><br />%s", escapedTitle, escapedMessage)
|
||||
formattedText := fmt.Sprintf("<b>%s</b><br /><br />%s", escapedTitle, message)
|
||||
|
||||
_, err := d.client.SendFormattedText(a.MatrixID, text, formattedText)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue