Skip to content

Commit 64bbc0c

Browse files
committed
Move default value of DisableNotification to model.
1 parent b1f89fc commit 64bbc0c

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

internal/model/notif_telegram.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package model
22

3+
import "github.com/crazy-max/diun/v4/pkg/utl"
4+
35
// NotifTelegramDefaultTemplateBody ...
46
const NotifTelegramDefaultTemplateBody = `Docker tag {{ if .Entry.Image.HubLink }}[{{ .Entry.Image }}]({{ .Entry.Image.HubLink }}){{ else }}{{ .Entry.Image }}{{ end }} which you subscribed to through {{ .Entry.Provider }} provider {{ if (eq .Entry.Status "new") }}is available{{ else }}has been updated{{ end }} on {{ .Entry.Image.Domain }} registry (triggered by {{ escapeMarkdown .Meta.Hostname }} host).`
57

@@ -23,4 +25,5 @@ func (s *NotifTelegram) GetDefaults() *NotifTelegram {
2325
// SetDefaults sets the default values
2426
func (s *NotifTelegram) SetDefaults() {
2527
s.TemplateBody = NotifTelegramDefaultTemplateBody
28+
s.DisableNotification = utl.NewFalse()
2629
}

internal/notif/telegram/client.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,15 @@ func (c *Client) Send(entry model.NotifEntry) error {
104104
return err
105105
}
106106

107-
disableNotification := false
108-
if c.cfg.DisableNotification != nil {
109-
disableNotification = *c.cfg.DisableNotification
110-
}
111-
112107
for _, cid := range parsedChatIDs {
113108
if len(cid.topics) > 0 {
114109
for _, topic := range cid.topics {
115-
if err = sendTelegramMessage(bot, cid.id, topic, string(body), disableNotification); err != nil {
110+
if err = sendTelegramMessage(bot, cid.id, topic, string(body), *c.cfg.DisableNotification); err != nil {
116111
return err
117112
}
118113
}
119114
} else {
120-
if err = sendTelegramMessage(bot, cid.id, 0, string(body), disableNotification); err != nil {
115+
if err = sendTelegramMessage(bot, cid.id, 0, string(body), *c.cfg.DisableNotification); err != nil {
121116
return err
122117
}
123118
}

0 commit comments

Comments
 (0)