Fix watch history order (#3653)

This commit is contained in:
Samantaz Fox 2023-05-03 00:34:04 +02:00
commit 1eb1bae370
No known key found for this signature in database
GPG key ID: F42821059186176E
3 changed files with 4 additions and 6 deletions

View file

@ -52,7 +52,7 @@ module Invidious::Database::Users
def mark_watched(user : User, vid : String) def mark_watched(user : User, vid : String)
request = <<-SQL request = <<-SQL
UPDATE users UPDATE users
SET watched = array_append(watched, $1) SET watched = array_append(array_remove(watched, $1), $1)
WHERE email = $2 WHERE email = $2
SQL SQL

View file

@ -76,7 +76,7 @@ module Invidious::Routes::Watch
end end
env.params.query.delete_all("iv_load_policy") env.params.query.delete_all("iv_load_policy")
if watched && preferences.watch_history && !watched.includes? id if watched && preferences.watch_history
Invidious::Database::Users.mark_watched(user.as(User), id) Invidious::Database::Users.mark_watched(user.as(User), id)
end end
@ -259,9 +259,7 @@ module Invidious::Routes::Watch
case action case action
when "action_mark_watched" when "action_mark_watched"
if !user.watched.includes? id Invidious::Database::Users.mark_watched(user, id)
Invidious::Database::Users.mark_watched(user, id)
end
when "action_mark_unwatched" when "action_mark_unwatched"
Invidious::Database::Users.mark_unwatched(user, id) Invidious::Database::Users.mark_unwatched(user, id)
else else

View file

@ -48,7 +48,7 @@ struct Invidious::User
if data["watch_history"]? if data["watch_history"]?
user.watched += data["watch_history"].as_a.map(&.as_s) user.watched += data["watch_history"].as_a.map(&.as_s)
user.watched.uniq! user.watched.reverse!.uniq!.reverse!
Invidious::Database::Users.update_watch_history(user) Invidious::Database::Users.update_watch_history(user)
end end