2020-11-06 23:19:54 +03:00
|
|
|
package view
|
|
|
|
|
2023-01-18 03:27:07 +03:00
|
|
|
import (
|
|
|
|
conf "github.com/muety/wakapi/config"
|
|
|
|
"github.com/muety/wakapi/models"
|
|
|
|
"time"
|
|
|
|
)
|
2021-12-16 14:39:41 +03:00
|
|
|
|
2020-11-06 23:19:54 +03:00
|
|
|
type SummaryViewModel struct {
|
2023-01-02 20:05:28 +03:00
|
|
|
Messages
|
2021-12-16 14:39:41 +03:00
|
|
|
*models.Summary
|
|
|
|
*models.SummaryParams
|
|
|
|
User *models.User
|
|
|
|
AvatarURL string
|
2022-03-27 22:56:13 +03:00
|
|
|
EditorColors map[string]string
|
2021-12-16 14:39:41 +03:00
|
|
|
LanguageColors map[string]string
|
2022-03-27 22:56:13 +03:00
|
|
|
OSColors map[string]string
|
2021-12-16 14:39:41 +03:00
|
|
|
ApiKey string
|
|
|
|
RawQuery string
|
2023-01-18 03:27:07 +03:00
|
|
|
UserFirstData time.Time
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s SummaryViewModel) UserDataExpiring() bool {
|
|
|
|
cfg := conf.Get()
|
|
|
|
return cfg.Subscriptions.Enabled &&
|
|
|
|
cfg.App.DataRetentionMonths > 0 &&
|
|
|
|
!s.UserFirstData.IsZero() &&
|
|
|
|
!s.User.HasActiveSubscription() &&
|
|
|
|
time.Now().AddDate(0, -cfg.App.DataRetentionMonths, 0).After(s.UserFirstData)
|
2020-11-06 23:19:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SummaryViewModel) WithSuccess(m string) *SummaryViewModel {
|
2023-01-02 20:05:28 +03:00
|
|
|
s.SetSuccess(m)
|
2020-11-06 23:19:54 +03:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SummaryViewModel) WithError(m string) *SummaryViewModel {
|
2023-01-02 20:05:28 +03:00
|
|
|
s.SetError(m)
|
2020-11-06 23:19:54 +03:00
|
|
|
return s
|
|
|
|
}
|