diff --git a/internal/database/migrations.go b/internal/database/migrations.go index e48217ad81a..065d271ee54 100644 --- a/internal/database/migrations.go +++ b/internal/database/migrations.go @@ -903,4 +903,9 @@ var migrations = []func(tx *sql.Tx) error{ _, err = tx.Exec(sql) return err }, + func(tx *sql.Tx) (err error) { + sql := `ALTER TABLE users ADD COLUMN cache_for_offline boolean default 'f'` + _, err = tx.Exec(sql) + return err + }, } diff --git a/internal/locale/translations/en_US.json b/internal/locale/translations/en_US.json index 71867ffe3e2..ca4dbeed5fa 100644 --- a/internal/locale/translations/en_US.json +++ b/internal/locale/translations/en_US.json @@ -377,6 +377,7 @@ "form.prefs.label.default_home_page": "Default home page", "form.prefs.label.categories_sorting_order": "Categories sorting", "form.prefs.label.mark_read_on_view": "Automatically mark entries as read when viewed", + "form.prefs.label.cache_for_offline": "Cache entries for offline reading", "form.prefs.fieldset.application_settings": "Application Settings", "form.prefs.fieldset.authentication_settings": "Authentication Settings", "form.prefs.fieldset.reader_settings": "Reader Settings", diff --git a/internal/model/user.go b/internal/model/user.go index 62aff600795..abf58afd234 100644 --- a/internal/model/user.go +++ b/internal/model/user.go @@ -36,6 +36,7 @@ type User struct { CategoriesSortingOrder string `json:"categories_sorting_order"` MarkReadOnView bool `json:"mark_read_on_view"` MediaPlaybackRate float64 `json:"media_playback_rate"` + CacheForOffline bool `json:"cache_for_offline"` } // UserCreationRequest represents the request to create a user. @@ -72,6 +73,7 @@ type UserModificationRequest struct { CategoriesSortingOrder *string `json:"categories_sorting_order"` MarkReadOnView *bool `json:"mark_read_on_view"` MediaPlaybackRate *float64 `json:"media_playback_rate"` + CacheForOffline bool `json:"cache_for_offline"` } // Patch updates the User object with the modification request. @@ -167,6 +169,10 @@ func (u *UserModificationRequest) Patch(user *User) { if u.MediaPlaybackRate != nil { user.MediaPlaybackRate = *u.MediaPlaybackRate } + + if u.CacheForOffline { + user.CacheForOffline = u.CacheForOffline + } } // UseTimezone converts last login date to the given timezone. diff --git a/internal/storage/user.go b/internal/storage/user.go index 4f30ac0da3e..552982d88e3 100644 --- a/internal/storage/user.go +++ b/internal/storage/user.go @@ -92,7 +92,8 @@ func (s *Storage) CreateUser(userCreationRequest *model.UserCreationRequest) (*m default_home_page, categories_sorting_order, mark_read_on_view, - media_playback_rate + media_playback_rate, + cache_for_offline ` tx, err := s.db.Begin() @@ -132,6 +133,7 @@ func (s *Storage) CreateUser(userCreationRequest *model.UserCreationRequest) (*m &user.CategoriesSortingOrder, &user.MarkReadOnView, &user.MediaPlaybackRate, + &user.CacheForOffline, ) if err != nil { tx.Rollback() @@ -189,9 +191,10 @@ func (s *Storage) UpdateUser(user *model.User) error { default_home_page=$20, categories_sorting_order=$21, mark_read_on_view=$22, - media_playback_rate=$23 + media_playback_rate=$23, + cache_for_offline=$24 WHERE - id=$24 + id=$25 ` _, err = s.db.Exec( @@ -219,6 +222,7 @@ func (s *Storage) UpdateUser(user *model.User) error { user.CategoriesSortingOrder, user.MarkReadOnView, user.MediaPlaybackRate, + user.CacheForOffline, user.ID, ) if err != nil { @@ -248,9 +252,10 @@ func (s *Storage) UpdateUser(user *model.User) error { default_home_page=$19, categories_sorting_order=$20, mark_read_on_view=$21, - media_playback_rate=$22 + media_playback_rate=$22, + cache_for_offline=$23 WHERE - id=$23 + id=$24 ` _, err := s.db.Exec( @@ -277,6 +282,7 @@ func (s *Storage) UpdateUser(user *model.User) error { user.CategoriesSortingOrder, user.MarkReadOnView, user.MediaPlaybackRate, + user.CacheForOffline, user.ID, ) @@ -325,7 +331,8 @@ func (s *Storage) UserByID(userID int64) (*model.User, error) { default_home_page, categories_sorting_order, mark_read_on_view, - media_playback_rate + media_playback_rate, + cache_for_offline FROM users WHERE @@ -361,7 +368,8 @@ func (s *Storage) UserByUsername(username string) (*model.User, error) { default_home_page, categories_sorting_order, mark_read_on_view, - media_playback_rate + media_playback_rate, + cache_for_offline FROM users WHERE @@ -397,7 +405,8 @@ func (s *Storage) UserByField(field, value string) (*model.User, error) { default_home_page, categories_sorting_order, mark_read_on_view, - media_playback_rate + media_playback_rate, + cache_for_offline FROM users WHERE @@ -440,7 +449,8 @@ func (s *Storage) UserByAPIKey(token string) (*model.User, error) { u.default_home_page, u.categories_sorting_order, u.mark_read_on_view, - media_playback_rate + media_playback_rate, + u.cache_for_offline FROM users u LEFT JOIN @@ -478,6 +488,7 @@ func (s *Storage) fetchUser(query string, args ...interface{}) (*model.User, err &user.CategoriesSortingOrder, &user.MarkReadOnView, &user.MediaPlaybackRate, + &user.CacheForOffline, ) if err == sql.ErrNoRows { @@ -586,7 +597,8 @@ func (s *Storage) Users() (model.Users, error) { default_home_page, categories_sorting_order, mark_read_on_view, - media_playback_rate + media_playback_rate, + cache_for_offline FROM users ORDER BY username ASC @@ -625,6 +637,7 @@ func (s *Storage) Users() (model.Users, error) { &user.CategoriesSortingOrder, &user.MarkReadOnView, &user.MediaPlaybackRate, + &user.CacheForOffline, ) if err != nil { diff --git a/internal/template/templates/views/settings.html b/internal/template/templates/views/settings.html index 0be77f626ba..c78cbc9b075 100644 --- a/internal/template/templates/views/settings.html +++ b/internal/template/templates/views/settings.html @@ -114,6 +114,7 @@