fix card link in notifications; card pointer was cached by template (#2096)
This commit is contained in:
parent
106a8e5b2e
commit
c6714a76bc
2 changed files with 25 additions and 12 deletions
|
@ -20,9 +20,9 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// card change notifications.
|
// card change notifications.
|
||||||
defAddCardNotify = "{{.Authors | printAuthors \"unknown_user\" }} has added the card {{.NewBlock | makeLink}}\n"
|
defAddCardNotify = "{{.Authors | printAuthors \"unknown_user\" }} has added the card {{. | makeLink}}\n"
|
||||||
defModifyCardNotify = "###### {{.Authors | printAuthors \"unknown_user\" }} has modified the card {{.Card | makeLink}}\n"
|
defModifyCardNotify = "###### {{.Authors | printAuthors \"unknown_user\" }} has modified the card {{. | makeLink}}\n"
|
||||||
defDeleteCardNotify = "{{.Authors | printAuthors \"unknown_user\" }} has deleted the card {{.Card | makeLink}}\n"
|
defDeleteCardNotify = "{{.Authors | printAuthors \"unknown_user\" }} has deleted the card {{. | makeLink}}\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -34,7 +34,7 @@ var (
|
||||||
// DiffConvOpts provides options when converting diffs to slack attachments.
|
// DiffConvOpts provides options when converting diffs to slack attachments.
|
||||||
type DiffConvOpts struct {
|
type DiffConvOpts struct {
|
||||||
Language string
|
Language string
|
||||||
MakeCardLink func(block *model.Block) string
|
MakeCardLink func(block *model.Block, board *model.Block, card *model.Block) string
|
||||||
Logger *mlog.Logger
|
Logger *mlog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,11 +49,15 @@ func getTemplate(name string, opts DiffConvOpts, def string) (*template.Template
|
||||||
t = template.New(key)
|
t = template.New(key)
|
||||||
|
|
||||||
if opts.MakeCardLink == nil {
|
if opts.MakeCardLink == nil {
|
||||||
opts.MakeCardLink = func(block *model.Block) string { return fmt.Sprintf("`%s`", block.Title) }
|
opts.MakeCardLink = func(block *model.Block, _ *model.Block, _ *model.Block) string {
|
||||||
|
return fmt.Sprintf("`%s`", block.Title)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
myFuncs := template.FuncMap{
|
myFuncs := template.FuncMap{
|
||||||
"getBoardDescription": getBoardDescription,
|
"getBoardDescription": getBoardDescription,
|
||||||
"makeLink": opts.MakeCardLink,
|
"makeLink": func(diff *Diff) string {
|
||||||
|
return opts.MakeCardLink(diff.NewBlock, diff.Board, diff.Card)
|
||||||
|
},
|
||||||
"stripNewlines": func(s string) string {
|
"stripNewlines": func(s string) string {
|
||||||
return strings.TrimSpace(strings.ReplaceAll(s, "\n", "¶ "))
|
return strings.TrimSpace(strings.ReplaceAll(s, "\n", "¶ "))
|
||||||
},
|
},
|
||||||
|
@ -151,6 +155,13 @@ func cardDiff2SlackAttachment(cardDiff *Diff, opts DiffConvOpts) (*mm_model.Slac
|
||||||
|
|
||||||
// at this point new and old block are non-nil
|
// at this point new and old block are non-nil
|
||||||
|
|
||||||
|
opts.Logger.Debug("cardDiff2SlackAttachment",
|
||||||
|
mlog.String("board_id", cardDiff.Board.ID),
|
||||||
|
mlog.String("card_id", cardDiff.Card.ID),
|
||||||
|
mlog.String("new_block_id", cardDiff.NewBlock.ID),
|
||||||
|
mlog.String("old_block_id", cardDiff.OldBlock.ID),
|
||||||
|
)
|
||||||
|
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
if err := execTemplate(buf, "ModifyCardNotify", opts, defModifyCardNotify, cardDiff); err != nil {
|
if err := execTemplate(buf, "ModifyCardNotify", opts, defModifyCardNotify, cardDiff); err != nil {
|
||||||
return nil, fmt.Errorf("cannot write notification for card %s: %w", cardDiff.NewBlock.ID, err)
|
return nil, fmt.Errorf("cannot write notification for card %s: %w", cardDiff.NewBlock.ID, err)
|
||||||
|
|
|
@ -154,11 +154,6 @@ func (n *notifier) notifySubscribers(hint *model.NotificationHint) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
n.logger.Debug("notifySubscribers - subscribers",
|
|
||||||
mlog.Any("hint", hint),
|
|
||||||
mlog.Int("sub_count", len(subs)),
|
|
||||||
)
|
|
||||||
|
|
||||||
// subs slice is sorted by `NotifiedAt`, therefore subs[0] contains the oldest NotifiedAt needed
|
// subs slice is sorted by `NotifiedAt`, therefore subs[0] contains the oldest NotifiedAt needed
|
||||||
oldestNotifiedAt := subs[0].NotifiedAt
|
oldestNotifiedAt := subs[0].NotifiedAt
|
||||||
|
|
||||||
|
@ -168,6 +163,13 @@ func (n *notifier) notifySubscribers(hint *model.NotificationHint) error {
|
||||||
return fmt.Errorf("could not get board & card for block %s: %w", hint.BlockID, err)
|
return fmt.Errorf("could not get board & card for block %s: %w", hint.BlockID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
n.logger.Debug("notifySubscribers - subscribers",
|
||||||
|
mlog.Any("hint", hint),
|
||||||
|
mlog.String("board_id", board.ID),
|
||||||
|
mlog.String("card_id", card.ID),
|
||||||
|
mlog.Int("sub_count", len(subs)),
|
||||||
|
)
|
||||||
|
|
||||||
dg := &diffGenerator{
|
dg := &diffGenerator{
|
||||||
container: c,
|
container: c,
|
||||||
board: board,
|
board: board,
|
||||||
|
@ -198,7 +200,7 @@ func (n *notifier) notifySubscribers(hint *model.NotificationHint) error {
|
||||||
|
|
||||||
opts := DiffConvOpts{
|
opts := DiffConvOpts{
|
||||||
Language: "en", // TODO: use correct language with i18n available on server.
|
Language: "en", // TODO: use correct language with i18n available on server.
|
||||||
MakeCardLink: func(block *model.Block) string {
|
MakeCardLink: func(block *model.Block, board *model.Block, card *model.Block) string {
|
||||||
return fmt.Sprintf("[%s](%s)", block.Title, utils.MakeCardLink(n.serverRoot, board.WorkspaceID, board.ID, card.ID))
|
return fmt.Sprintf("[%s](%s)", block.Title, utils.MakeCardLink(n.serverRoot, board.WorkspaceID, board.ID, card.ID))
|
||||||
},
|
},
|
||||||
Logger: n.logger,
|
Logger: n.logger,
|
||||||
|
|
Loading…
Reference in a new issue