Cherry pick to main for add board link in bot notification (#3272)
Co-authored-by: Varghese Jose <varghese.jose@tutanota.com> Co-authored-by: Hosted Weblate <hosted@weblate.org> Co-authored-by: jprusch <rs@schaeferbarthold.de>
This commit is contained in:
parent
ca922dbc1e
commit
853c2950f5
5 changed files with 27 additions and 9 deletions
|
@ -21,7 +21,7 @@ import (
|
|||
const (
|
||||
// card change notifications.
|
||||
defAddCardNotify = "{{.Authors | printAuthors \"unknown_user\" }} has added the card {{. | makeLink}}\n"
|
||||
defModifyCardNotify = "###### {{.Authors | printAuthors \"unknown_user\" }} has modified the card {{. | makeLink}}\n"
|
||||
defModifyCardNotify = "###### {{.Authors | printAuthors \"unknown_user\" }} has modified the card {{. | makeLink}} on the board {{. | makeBoardLink}}\n"
|
||||
defDeleteCardNotify = "{{.Authors | printAuthors \"unknown_user\" }} has deleted the card {{. | makeLink}}\n"
|
||||
)
|
||||
|
||||
|
@ -35,6 +35,7 @@ var (
|
|||
type DiffConvOpts struct {
|
||||
Language string
|
||||
MakeCardLink func(block *model.Block, board *model.Board, card *model.Block) string
|
||||
MakeBoardLink func(board *model.Board) string
|
||||
Logger *mlog.Logger
|
||||
}
|
||||
|
||||
|
@ -53,11 +54,20 @@ func getTemplate(name string, opts DiffConvOpts, def string) (*template.Template
|
|||
return fmt.Sprintf("`%s`", block.Title)
|
||||
}
|
||||
}
|
||||
|
||||
if opts.MakeBoardLink == nil {
|
||||
opts.MakeBoardLink = func(board *model.Board) string {
|
||||
return fmt.Sprintf("`%s`", board.Title)
|
||||
}
|
||||
}
|
||||
myFuncs := template.FuncMap{
|
||||
"getBoardDescription": getBoardDescription,
|
||||
"makeLink": func(diff *Diff) string {
|
||||
return opts.MakeCardLink(diff.NewBlock, diff.Board, diff.Card)
|
||||
},
|
||||
"makeBoardLink": func(diff *Diff) string {
|
||||
return opts.MakeBoardLink(diff.Board)
|
||||
},
|
||||
"stripNewlines": func(s string) string {
|
||||
return strings.TrimSpace(strings.ReplaceAll(s, "\n", "¶ "))
|
||||
},
|
||||
|
|
|
@ -204,6 +204,9 @@ func (n *notifier) notifySubscribers(hint *model.NotificationHint) error {
|
|||
MakeCardLink: func(block *model.Block, board *model.Board, card *model.Block) string {
|
||||
return fmt.Sprintf("[%s](%s)", block.Title, utils.MakeCardLink(n.serverRoot, board.TeamID, board.ID, card.ID))
|
||||
},
|
||||
MakeBoardLink: func(board *model.Board) string {
|
||||
return fmt.Sprintf("[%s](%s)", board.Title, utils.MakeBoardLink(n.serverRoot, board.TeamID, board.ID))
|
||||
},
|
||||
Logger: n.logger,
|
||||
}
|
||||
|
||||
|
|
|
@ -24,11 +24,12 @@ func (pd *PluginDelivery) MentionDeliver(mentionedUser *mm_model.User, extract s
|
|||
return "", fmt.Errorf("cannot get direct channel: %w", err)
|
||||
}
|
||||
link := utils.MakeCardLink(pd.serverRoot, evt.Board.TeamID, evt.Board.ID, evt.Card.ID)
|
||||
boardLink := utils.MakeBoardLink(pd.serverRoot, evt.Board.TeamID, evt.Board.ID)
|
||||
|
||||
post := &mm_model.Post{
|
||||
UserId: pd.botID,
|
||||
ChannelId: channel.Id,
|
||||
Message: formatMessage(author.Username, extract, evt.Card.Title, link, evt.BlockChanged),
|
||||
Message: formatMessage(author.Username, extract, evt.Card.Title, link, evt.BlockChanged, boardLink, evt.Board.Title),
|
||||
}
|
||||
return mentionedUser.Id, pd.api.CreatePost(post)
|
||||
}
|
||||
|
|
|
@ -11,14 +11,14 @@ import (
|
|||
|
||||
const (
|
||||
// TODO: localize these when i18n is available.
|
||||
defCommentTemplate = "@%s mentioned you in a comment on the card [%s](%s)\n> %s"
|
||||
defDescriptionTemplate = "@%s mentioned you in the card [%s](%s)\n> %s"
|
||||
defCommentTemplate = "@%s mentioned you in a comment on the card [%s](%s) in board [%s](%s)\n> %s"
|
||||
defDescriptionTemplate = "@%s mentioned you in the card [%s](%s) in board [%s](%s)\n> %s"
|
||||
)
|
||||
|
||||
func formatMessage(author string, extract string, card string, link string, block *model.Block) string {
|
||||
func formatMessage(author string, extract string, card string, link string, block *model.Block, boardLink string, board string) string {
|
||||
template := defDescriptionTemplate
|
||||
if block.Type == model.TypeComment {
|
||||
template = defCommentTemplate
|
||||
}
|
||||
return fmt.Sprintf(template, author, card, link, extract)
|
||||
return fmt.Sprintf(template, author, card, link, board, boardLink, extract)
|
||||
}
|
||||
|
|
|
@ -9,3 +9,7 @@ import "fmt"
|
|||
func MakeCardLink(serverRoot string, teamID string, boardID string, cardID string) string {
|
||||
return fmt.Sprintf("%s/team/%s/%s/0/%s", serverRoot, teamID, boardID, cardID)
|
||||
}
|
||||
|
||||
func MakeBoardLink(serverRoot string, teamID string, board string) string {
|
||||
return fmt.Sprintf("%s/team/%s/%s", serverRoot, teamID, board)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue