1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

feat: subscription expiry notification mails

This commit is contained in:
Ferdinand Mütsch
2022-12-29 17:12:34 +01:00
parent dc0bcbe65d
commit 50c54685ec
11 changed files with 269 additions and 27 deletions

View File

@ -135,6 +135,22 @@ func (u *User) HasActiveSubscriptionStrict() bool {
return u.SubscribedUntil != nil && u.SubscribedUntil.T().After(time.Now())
}
// SubscriptionExpiredSince returns if a user's subscription has expiration and the duration since when that happened.
// Returns (false, <negative duration>), if subscription hasn't expired, yet.
// Returns (false, 0), if subscriptions are not enabled in the first place.
// Returns (true, <very long duration>), if the user has never had a subscription.
func (u *User) SubscriptionExpiredSince() (bool, time.Duration) {
cfg := conf.Get()
if !cfg.Subscriptions.Enabled {
return false, 0
}
if u.SubscribedUntil == nil {
return true, 99 * 365 * 24 * time.Hour
}
diff := time.Now().Sub(u.SubscribedUntil.T())
return diff >= 0, diff
}
func (u *User) MinDataAge() time.Time {
retentionMonths := conf.Get().App.DataRetentionMonths
if retentionMonths <= 0 || u.HasActiveSubscription() {