2018-05-12 03:15:16 +00:00
|
|
|
package events
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/kirsle/blog/internal/mail"
|
|
|
|
"github.com/kirsle/blog/models/events"
|
|
|
|
"github.com/kirsle/blog/models/settings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func notifyUser(ev *events.Event, rsvp events.RSVP) {
|
|
|
|
var (
|
|
|
|
email = rsvp.GetEmail()
|
|
|
|
sms = rsvp.GetSMS()
|
|
|
|
)
|
|
|
|
s, _ := settings.Load()
|
|
|
|
|
2018-05-12 04:29:18 +00:00
|
|
|
// Can we get an "auto-login" link?
|
|
|
|
var claimURL string
|
|
|
|
if rsvp.Contact.Secret != "" {
|
|
|
|
claimURL = fmt.Sprintf("%s/c/%s?e=%d",
|
|
|
|
strings.Trim(s.Site.URL, "/"),
|
|
|
|
rsvp.Contact.Secret,
|
|
|
|
ev.ID,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-05-12 03:15:16 +00:00
|
|
|
// Do they have... an e-mail address?
|
|
|
|
if email != "" {
|
2018-05-12 04:29:18 +00:00
|
|
|
go mail.SendEmail(mail.Email{
|
2018-05-12 03:15:16 +00:00
|
|
|
To: email,
|
|
|
|
Subject: fmt.Sprintf("Invitation to: %s", ev.Title),
|
|
|
|
Data: map[string]interface{}{
|
2018-05-12 04:29:18 +00:00
|
|
|
"RSVP": rsvp,
|
|
|
|
"Event": ev,
|
|
|
|
"URL": strings.Trim(s.Site.URL, "/") + "/e/" + ev.Fragment,
|
|
|
|
"ClaimURL": claimURL,
|
2018-05-12 03:15:16 +00:00
|
|
|
},
|
|
|
|
Template: ".email/event-invite.gohtml",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// An SMS number?
|
|
|
|
if sms != "" {
|
2018-05-12 04:29:18 +00:00
|
|
|
// TODO: Twilio
|
2018-05-12 03:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rsvp.Notified = true
|
|
|
|
rsvp.Save()
|
|
|
|
}
|