Rename Letters [letters] config section to Email [email]

This commit is contained in:
Matt Baer 2023-09-25 14:26:41 -04:00
parent 221d0d7dbb
commit cc75be1eb5
5 changed files with 16 additions and 16 deletions

View File

@ -876,16 +876,16 @@ func viewEditCollection(app *App, u *User, w http.ResponseWriter, r *http.Reques
*Collection *Collection
Silenced bool Silenced bool
config.LettersCfg config.EmailCfg
LetterReplyTo string LetterReplyTo string
}{ }{
UserPage: NewUserPage(app, r, u, "Edit "+c.DisplayTitle(), flashes), UserPage: NewUserPage(app, r, u, "Edit "+c.DisplayTitle(), flashes),
Collection: c, Collection: c,
Silenced: silenced, Silenced: silenced,
LettersCfg: app.cfg.Letters, EmailCfg: app.cfg.Email,
} }
obj.UserPage.CollAlias = c.Alias obj.UserPage.CollAlias = c.Alias
if obj.LettersCfg.Enabled() { if obj.EmailCfg.Enabled() {
obj.LetterReplyTo = app.db.GetCollectionAttribute(c.ID, collAttrLetterReplyTo) obj.LetterReplyTo = app.db.GetCollectionAttribute(c.ID, collAttrLetterReplyTo)
} }

6
app.go
View File

@ -428,10 +428,10 @@ func Initialize(apper Apper, debug bool) (*App, error) {
initActivityPub(apper.App()) initActivityPub(apper.App())
if apper.App().cfg.Letters.Domain != "" || apper.App().cfg.Letters.MailgunPrivate != "" { if apper.App().cfg.Email.Domain != "" || apper.App().cfg.Email.MailgunPrivate != "" {
if apper.App().cfg.Letters.Domain == "" { if apper.App().cfg.Email.Domain == "" {
log.Error("[FAILED] Starting publish jobs queue: no [letters]domain config value set.") log.Error("[FAILED] Starting publish jobs queue: no [letters]domain config value set.")
} else if apper.App().cfg.Letters.MailgunPrivate == "" { } else if apper.App().cfg.Email.MailgunPrivate == "" {
log.Error("[FAILED] Starting publish jobs queue: no [letters]mailgun_private config value set.") log.Error("[FAILED] Starting publish jobs queue: no [letters]mailgun_private config value set.")
} else { } else {
log.Info("Starting publish jobs queue...") log.Info("Starting publish jobs queue...")

View File

@ -170,7 +170,7 @@ type (
DisablePasswordAuth bool `ini:"disable_password_auth"` DisablePasswordAuth bool `ini:"disable_password_auth"`
} }
LettersCfg struct { EmailCfg struct {
Domain string `ini:"domain"` Domain string `ini:"domain"`
MailgunPrivate string `ini:"mailgun_private"` MailgunPrivate string `ini:"mailgun_private"`
} }
@ -180,7 +180,7 @@ type (
Server ServerCfg `ini:"server"` Server ServerCfg `ini:"server"`
Database DatabaseCfg `ini:"database"` Database DatabaseCfg `ini:"database"`
App AppCfg `ini:"app"` App AppCfg `ini:"app"`
Letters LettersCfg `ini:"letters"` Email EmailCfg `ini:"email"`
SlackOauth SlackOauthCfg `ini:"oauth.slack"` SlackOauth SlackOauthCfg `ini:"oauth.slack"`
WriteAsOauth WriteAsOauthCfg `ini:"oauth.writeas"` WriteAsOauth WriteAsOauthCfg `ini:"oauth.writeas"`
GitlabOauth GitlabOauthCfg `ini:"oauth.gitlab"` GitlabOauth GitlabOauthCfg `ini:"oauth.gitlab"`
@ -241,7 +241,7 @@ func (ac *AppCfg) LandingPath() string {
return ac.Landing return ac.Landing
} }
func (lc LettersCfg) Enabled() bool { func (lc EmailCfg) Enabled() bool {
return lc.Domain != "" && lc.MailgunPrivate != "" return lc.Domain != "" && lc.MailgunPrivate != ""
} }

View File

@ -313,8 +313,8 @@ Originally published on ` + p.Collection.DisplayTitle() + ` (` + p.Collection.Ca
Sent to %recipient.to%. Unsubscribe: ` + p.Collection.CanonicalURL() + `email/unsubscribe/%recipient.id%?t=%recipient.token%` Sent to %recipient.to%. Unsubscribe: ` + p.Collection.CanonicalURL() + `email/unsubscribe/%recipient.id%?t=%recipient.token%`
gun := mailgun.NewMailgun(app.cfg.Letters.Domain, app.cfg.Letters.MailgunPrivate) gun := mailgun.NewMailgun(app.cfg.Email.Domain, app.cfg.Email.MailgunPrivate)
m := mailgun.NewMessage(p.Collection.DisplayTitle()+" <"+p.Collection.Alias+"@"+app.cfg.Letters.Domain+">", stripmd.Strip(p.DisplayTitle()), plainMsg) m := mailgun.NewMessage(p.Collection.DisplayTitle()+" <"+p.Collection.Alias+"@"+app.cfg.Email.Domain+">", stripmd.Strip(p.DisplayTitle()), plainMsg)
replyTo := app.db.GetCollectionAttribute(collID, collAttrLetterReplyTo) replyTo := app.db.GetCollectionAttribute(collID, collAttrLetterReplyTo)
if replyTo != "" { if replyTo != "" {
m.SetReplyTo(replyTo) m.SetReplyTo(replyTo)
@ -443,14 +443,14 @@ func sendSubConfirmEmail(app *App, c *Collection, email, subID, token string) er
} }
// Send email // Send email
gun := mailgun.NewMailgun(app.cfg.Letters.Domain, app.cfg.Letters.MailgunPrivate) gun := mailgun.NewMailgun(app.cfg.Email.Domain, app.cfg.Email.MailgunPrivate)
plainMsg := "Confirm your subscription to " + c.DisplayTitle() + ` (` + c.CanonicalURL() + `) to start receiving future posts. Simply click the following link (or copy and paste it into your browser): plainMsg := "Confirm your subscription to " + c.DisplayTitle() + ` (` + c.CanonicalURL() + `) to start receiving future posts. Simply click the following link (or copy and paste it into your browser):
` + c.CanonicalURL() + "email/confirm/" + subID + "?t=" + token + ` ` + c.CanonicalURL() + "email/confirm/" + subID + "?t=" + token + `
If you didn't subscribe to this site or you're not sure why you're getting this email, you can delete it. You won't be subscribed or receive any future emails.` If you didn't subscribe to this site or you're not sure why you're getting this email, you can delete it. You won't be subscribed or receive any future emails.`
m := mailgun.NewMessage(c.DisplayTitle()+" <"+c.Alias+"@"+app.cfg.Letters.Domain+">", "Confirm your subscription to "+c.DisplayTitle(), plainMsg, fmt.Sprintf("<%s>", email)) m := mailgun.NewMessage(c.DisplayTitle()+" <"+c.Alias+"@"+app.cfg.Email.Domain+">", "Confirm your subscription to "+c.DisplayTitle(), plainMsg, fmt.Sprintf("<%s>", email))
m.AddTag("Email Verification") m.AddTag("Email Verification")
m.SetHtml(`<html> m.SetHtml(`<html>

View File

@ -657,7 +657,7 @@ func newPost(app *App, w http.ResponseWriter, r *http.Request) error {
if !app.cfg.App.Private && app.cfg.App.Federation && !newPost.Created.After(time.Now()) { if !app.cfg.App.Private && app.cfg.App.Federation && !newPost.Created.After(time.Now()) {
go federatePost(app, newPost, newPost.Collection.ID, false) go federatePost(app, newPost, newPost.Collection.ID, false)
} }
if app.cfg.Letters.Enabled() && newPost.Collection.EmailSubsEnabled() { if app.cfg.Email.Enabled() && newPost.Collection.EmailSubsEnabled() {
go app.db.InsertJob(&PostJob{ go app.db.InsertJob(&PostJob{
PostID: newPost.ID, PostID: newPost.ID,
Action: "email", Action: "email",
@ -973,7 +973,7 @@ func addPost(app *App, w http.ResponseWriter, r *http.Request) error {
go federatePost(app, pRes.Post, pRes.Post.Collection.ID, false) go federatePost(app, pRes.Post, pRes.Post.Collection.ID, false)
} }
} }
if app.cfg.Letters.Enabled() && pRes.Post.Collection.EmailSubsEnabled() { if app.cfg.Email.Enabled() && pRes.Post.Collection.EmailSubsEnabled() {
go app.db.InsertJob(&PostJob{ go app.db.InsertJob(&PostJob{
PostID: pRes.Post.ID, PostID: pRes.Post.ID,
Action: "email", Action: "email",
@ -1558,7 +1558,7 @@ Are you sure it was ever here?`,
} else { } else {
p.extractData() p.extractData()
p.Content = strings.Replace(p.Content, "<!--more-->", "", 1) p.Content = strings.Replace(p.Content, "<!--more-->", "", 1)
if app.cfg.Letters.Enabled() && c.EmailSubsEnabled() { if app.cfg.Email.Enabled() && c.EmailSubsEnabled() {
// TODO: indicate plan is inactive or subs disabled when OWNER is viewing their own post. // TODO: indicate plan is inactive or subs disabled when OWNER is viewing their own post.
if u != nil && u.IsEmailSubscriber(app, c.ID) { if u != nil && u.IsEmailSubscriber(app, c.ID) {
p.Content = strings.Replace(p.Content, "<!--emailsub-->", `<p id="emailsub">You're subscribed to email updates. <a href="/api/collections/`+c.Alias+`/email/unsubscribe?slug=`+p.Slug.String+`">Unsubscribe</a>.</p>`, -1) p.Content = strings.Replace(p.Content, "<!--emailsub-->", `<p id="emailsub">You're subscribed to email updates. <a href="/api/collections/`+c.Alias+`/email/unsubscribe?slug=`+p.Slug.String+`">Unsubscribe</a>.</p>`, -1)