simplify family nudge email
This commit is contained in:
@@ -2,9 +2,6 @@ package email
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
t "time"
|
||||
|
||||
"github.com/avct/uasurfer"
|
||||
"github.com/ente-io/museum/ente"
|
||||
"github.com/ente-io/museum/pkg/controller/lock"
|
||||
@@ -13,6 +10,7 @@ import (
|
||||
"github.com/ente-io/museum/pkg/utils/time"
|
||||
"github.com/ente-io/stacktrace"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -245,29 +243,24 @@ func (c *EmailNotificationController) setStorageLimitExceededMailerJobStatus(isS
|
||||
}
|
||||
|
||||
func (c *EmailNotificationController) SendFamilyNudgeEmail() error {
|
||||
thirtyDaysDuration := 30 * 24 * t.Hour
|
||||
subscribedUsers, subUsersErr := c.UserRepo.GetSubscribedUsersWithoutFamily((30))
|
||||
subscribedUsers, subUsersErr := c.UserRepo.GetSubscribedUsersWithoutFamily(30)
|
||||
if subUsersErr != nil {
|
||||
return stacktrace.Propagate(subUsersErr, "Failed to get subscribers")
|
||||
}
|
||||
for _, user := range subscribedUsers {
|
||||
creationTime := t.Unix(0, user.CreationTime)
|
||||
timeSinceCreation := t.Since(creationTime)
|
||||
if timeSinceCreation >= thirtyDaysDuration {
|
||||
lastNudgeSent, err := c.NotificationHistoryRepo.GetLastNotificationTime(user.ID, FilesCollectedTemplateID)
|
||||
if err != nil {
|
||||
log.Error("Failed to set Notification History")
|
||||
}
|
||||
lastNudgeSent, err := c.NotificationHistoryRepo.GetLastNotificationTime(user.ID, FilesCollectedTemplateID)
|
||||
if err != nil {
|
||||
log.Error("Failed to set Notification History")
|
||||
}
|
||||
|
||||
if lastNudgeSent == 0 {
|
||||
go func(userEmails []string) {
|
||||
err := email.SendTemplatedEmail(userEmails, "team@ente.io", "team@ente.io", FamilyNudgeSubject, FamilyNudgeEmailTemplate, nil, nil)
|
||||
if err != nil {
|
||||
log.Error("Failed to send family nudge email: ", err)
|
||||
}
|
||||
}([]string{user.Email})
|
||||
c.NotificationHistoryRepo.SetLastNotificationTimeToNow(user.ID, FamilyNudgeTemplateID)
|
||||
}
|
||||
if lastNudgeSent == 0 {
|
||||
go func(userEmails []string) {
|
||||
err := email.SendTemplatedEmail(userEmails, "team@ente.io", "team@ente.io", FamilyNudgeSubject, FamilyNudgeEmailTemplate, nil, nil)
|
||||
if err != nil {
|
||||
log.Error("Failed to send family nudge email: ", err)
|
||||
}
|
||||
}([]string{user.Email})
|
||||
c.NotificationHistoryRepo.SetLastNotificationTimeToNow(user.ID, FamilyNudgeTemplateID)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -129,14 +129,15 @@ func (repo *UserRepository) GetAll(sinceTime int64, tillTime int64) ([]ente.User
|
||||
return users, nil
|
||||
}
|
||||
|
||||
// GetSubscribedUsers will return the list of all subscribed.
|
||||
// GetSubscribedUsersWithoutFamily returns notification candidates who are on paid plan
|
||||
// but not part of any family plan.
|
||||
func (repo *UserRepository) GetSubscribedUsersWithoutFamily(accountAgeInDays int64) ([]ente.User, error) {
|
||||
rows, err := repo.DB.Query(`SELECT u.user_id, u.encrypted_email, u.email_decryption_nonce, u.email_hash, s.created_at
|
||||
FROM subscriptions s
|
||||
INNER JOIN users u ON s.user_id = u.user_id
|
||||
WHERE u.creation_time <= $1 AND u.family_admin_id IS NULL
|
||||
AND s.product_id != 'free'
|
||||
AND u.email_hash NOT LIKE 'deleted+'`, time.MicrosecondBeforeDays(int(accountAgeInDays)))
|
||||
AND u.encrypted_email IS NOT NULL`, time.MicrosecondBeforeDays(int(accountAgeInDays)))
|
||||
if err != nil {
|
||||
return nil, stacktrace.Propagate(err, "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user