summaryrefslogtreecommitdiff
diff options
from:
to:
context:
space:
mode:
-rw-r--r--internal/mailer/mailer.go33
-rw-r--r--internal/router/lang-user-unsubscribe.go2
2 files changed, 22 insertions, 13 deletions
diff --git a/internal/mailer/mailer.go b/internal/mailer/mailer.go
index 847ebde..d6dbd17 100644
--- a/internal/mailer/mailer.go
+++ b/internal/mailer/mailer.go
@@ -349,8 +349,8 @@ func (m *Mailer) GetSubscriptions(userId string) (subscriptionType SubscriptionT
defer func(tx *sql.Tx) {
if err = tx.Commit(); err != nil {
tx.Rollback()
- slog.Debug("ended db transaction", slog.String("method", "GetSubscriptions"))
}
+ slog.Debug("ended db transaction", slog.String("method", "GetSubscriptions"))
}(tx)
hash := m.GetHash(userId)
@@ -452,21 +452,11 @@ rowLoop:
continue
}
- email, lang, err := m.GetInfo(userId)
- if err != nil {
- slog.Warn("failed to get info about the user", slog.String("error", err.Error()), slog.Int("index", i), slog.String("user_id", base64.RawStdEncoding.EncodeToString(userId)))
- continue
- }
-
- if lang != post.Lang {
- continue
- }
-
if tagsString == "_all" {
usersToSend = append(usersToSend, struct {
userId []byte
email string
- }{userId, email})
+ }{userId, ""})
continue
}
@@ -476,7 +466,7 @@ rowLoop:
usersToSend = append(usersToSend, struct {
userId []byte
email string
- }{userId, email})
+ }{userId, ""})
continue rowLoop
}
}
@@ -486,8 +476,25 @@ rowLoop:
rows.Close()
slog.Debug("ended db transaction", slog.String("method", "NewPost"))
+ for i := range usersToSend {
+ email, lang, err := m.GetInfo(usersToSend[i].userId)
+ if err != nil {
+ slog.Warn("failed to get info about the user", slog.String("error", err.Error()), slog.Int("index", i), slog.String("user_id", base64.RawStdEncoding.EncodeToString(userId)))
+ continue
+ }
+
+ if lang != post.Lang {
+ continue
+ }
+
+ usersToSend[i].email = email
+ }
+
messages := make([]*mail.Msg, 0, len(usersToSend))
for _, user := range usersToSend {
+ if user.email == "" {
+ continue
+ }
unsubscribeCodeBytes := make([]byte, 8)
rand.Read(unsubscribeCodeBytes)
unsubscribeCode := binary.LittleEndian.Uint64(unsubscribeCodeBytes)
diff --git a/internal/router/lang-user-unsubscribe.go b/internal/router/lang-user-unsubscribe.go
index 81d1bfb..c39f5e7 100644
--- a/internal/router/lang-user-unsubscribe.go
+++ b/internal/router/lang-user-unsubscribe.go
@@ -35,11 +35,13 @@ func Lang_User_Unsubscribe(l map[string]*locale.LocaleConfig, langs []config.Ava
statusText = l[lang].UnsubscribePage.UnsetCode
status = fiber.ErrBadRequest.Code
} else if clientError, serverError := Mailer.Unsubscribe(unsubscribeCode); clientError != nil {
+ slog.Info("got a client error when unsubscribing", slog.String("error", clientError.Error()))
statusColor = "255, 0, 0"
statusEmoji = "(͠≖~≖ ͡ )"
statusText = l[lang].UnsubscribePage.InvalidCode
status = fiber.ErrBadRequest.Code
} else if serverError != nil {
+ slog.Error("got a server error when unsubscribing", slog.String("error", serverError.Error()))
statusColor = "255, 128, 0"
statusEmoji = "( ˶°ㅁ°) !!"
statusText = l[lang].UnsubscribePage.OnServerError