Refactor manager.CampaignMessage's exposed fields
This commit is contained in:
parent
a0d9a4771a
commit
ca032c89d6
3 changed files with 13 additions and 6 deletions
|
@ -187,7 +187,7 @@ func handlePreviewCampaign(c echo.Context) error {
|
|||
fmt.Sprintf("Error rendering message: %v", err))
|
||||
}
|
||||
|
||||
return c.HTML(http.StatusOK, string(m.Body))
|
||||
return c.HTML(http.StatusOK, string(m.Body()))
|
||||
}
|
||||
|
||||
// handleCreateCampaign handles campaign creation.
|
||||
|
@ -562,7 +562,7 @@ func sendTestMessage(sub models.Subscriber, camp *models.Campaign, app *App) err
|
|||
fmt.Sprintf("Error rendering message: %v", err))
|
||||
}
|
||||
|
||||
if err := app.messenger.Push(camp.FromEmail, []string{sub.Email}, camp.Subject, m.Body, nil); err != nil {
|
||||
if err := app.messenger.Push(camp.FromEmail, []string{sub.Email}, camp.Subject, m.Body(), nil); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -65,10 +65,10 @@ type Manager struct {
|
|||
type CampaignMessage struct {
|
||||
Campaign *models.Campaign
|
||||
Subscriber models.Subscriber
|
||||
Body []byte
|
||||
|
||||
from string
|
||||
to string
|
||||
body []byte
|
||||
unsubURL string
|
||||
}
|
||||
|
||||
|
@ -263,7 +263,7 @@ func (m *Manager) SpawnWorkers() {
|
|||
}
|
||||
|
||||
err := m.messengers[msg.Campaign.MessengerID].Push(
|
||||
msg.from, []string{msg.to}, msg.Campaign.Subject, msg.Body, nil)
|
||||
msg.from, []string{msg.to}, msg.Campaign.Subject, msg.body, nil)
|
||||
if err != nil {
|
||||
m.logger.Printf("error sending message in campaign %s: %v", msg.Campaign.Name, err)
|
||||
|
||||
|
@ -472,6 +472,13 @@ func (m *CampaignMessage) Render() error {
|
|||
if err := m.Campaign.Tpl.ExecuteTemplate(&out, models.BaseTpl, m); err != nil {
|
||||
return err
|
||||
}
|
||||
m.Body = out.Bytes()
|
||||
m.body = out.Bytes()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Body returns a copy of the message body.
|
||||
func (m *CampaignMessage) Body() []byte {
|
||||
out := make([]byte, len(m.body))
|
||||
copy(out, m.body)
|
||||
return out
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ func handlePreviewTemplate(c echo.Context) error {
|
|||
fmt.Sprintf("Error rendering message: %v", err))
|
||||
}
|
||||
|
||||
return c.HTML(http.StatusOK, string(m.Body))
|
||||
return c.HTML(http.StatusOK, string(m.Body()))
|
||||
}
|
||||
|
||||
// handleCreateTemplate handles template creation.
|
||||
|
|
Loading…
Reference in a new issue