1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

feat: mark media as read when playback reaches 90%

This commit is contained in:
Loïc Doubinine 2024-07-28 21:29:45 +02:00 committed by GitHub
parent 37309adbc0
commit 4f55361f5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 278 additions and 76 deletions

View file

@ -11,6 +11,16 @@ import (
"miniflux.app/v2/internal/model"
)
// MarkReadBehavior list all possible behaviors for automatically marking an entry as read
type MarkReadBehavior string
var (
NoAutoMarkAsRead MarkReadBehavior = "no-auto"
MarkAsReadOnView MarkReadBehavior = "on-view"
MarkAsReadOnViewButWaitForPlayerCompletion MarkReadBehavior = "on-view-but-wait-for-player-completion"
MarkAsReadOnlyOnPlayerCompletion MarkReadBehavior = "on-player-completion"
)
// SettingsForm represents the settings form.
type SettingsForm struct {
Username string
@ -33,9 +43,45 @@ type SettingsForm struct {
DefaultHomePage string
CategoriesSortingOrder string
MarkReadOnView bool
MediaPlaybackRate float64
BlockFilterEntryRules string
KeepFilterEntryRules string
// MarkReadBehavior is a string representation of the MarkReadOnView and MarkReadOnMediaPlayerCompletion fields together
MarkReadBehavior MarkReadBehavior
MediaPlaybackRate float64
BlockFilterEntryRules string
KeepFilterEntryRules string
}
// MarkAsReadBehavior returns the MarkReadBehavior from the given MarkReadOnView and MarkReadOnMediaPlayerCompletion values.
// Useful to convert the values from the User model to the form
func MarkAsReadBehavior(markReadOnView, markReadOnMediaPlayerCompletion bool) MarkReadBehavior {
switch {
case markReadOnView && !markReadOnMediaPlayerCompletion:
return MarkAsReadOnView
case markReadOnView && markReadOnMediaPlayerCompletion:
return MarkAsReadOnViewButWaitForPlayerCompletion
case !markReadOnView && markReadOnMediaPlayerCompletion:
return MarkAsReadOnlyOnPlayerCompletion
case !markReadOnView && !markReadOnMediaPlayerCompletion:
fallthrough // Explicit defaulting
default:
return NoAutoMarkAsRead
}
}
// ExtractMarkAsReadBehavior returns the MarkReadOnView and MarkReadOnMediaPlayerCompletion values from the given MarkReadBehavior.
// Useful to extract the values from the form to the User model
func ExtractMarkAsReadBehavior(behavior MarkReadBehavior) (markReadOnView, markReadOnMediaPlayerCompletion bool) {
switch behavior {
case MarkAsReadOnView:
return true, false
case MarkAsReadOnViewButWaitForPlayerCompletion:
return true, true
case MarkAsReadOnlyOnPlayerCompletion:
return false, true
case NoAutoMarkAsRead:
fallthrough // Explicit defaulting
default:
return false, false
}
}
// Merge updates the fields of the given user.
@ -57,11 +103,14 @@ func (s *SettingsForm) Merge(user *model.User) *model.User {
user.DefaultReadingSpeed = s.DefaultReadingSpeed
user.DefaultHomePage = s.DefaultHomePage
user.CategoriesSortingOrder = s.CategoriesSortingOrder
user.MarkReadOnView = s.MarkReadOnView
user.MediaPlaybackRate = s.MediaPlaybackRate
user.BlockFilterEntryRules = s.BlockFilterEntryRules
user.KeepFilterEntryRules = s.KeepFilterEntryRules
MarkReadOnView, MarkReadOnMediaPlayerCompletion := ExtractMarkAsReadBehavior(s.MarkReadBehavior)
user.MarkReadOnView = MarkReadOnView
user.MarkReadOnMediaPlayerCompletion = MarkReadOnMediaPlayerCompletion
if s.Password != "" {
user.Password = s.Password
}
@ -136,6 +185,7 @@ func NewSettingsForm(r *http.Request) *SettingsForm {
DefaultHomePage: r.FormValue("default_home_page"),
CategoriesSortingOrder: r.FormValue("categories_sorting_order"),
MarkReadOnView: r.FormValue("mark_read_on_view") == "1",
MarkReadBehavior: MarkReadBehavior(r.FormValue("mark_read_behavior")),
MediaPlaybackRate: mediaPlaybackRate,
BlockFilterEntryRules: r.FormValue("block_filter_entry_rules"),
KeepFilterEntryRules: r.FormValue("keep_filter_entry_rules"),