partial support for history details in history page

This commit is contained in:
Fijxu 2024-12-24 14:21:42 -03:00
parent ee6d2b5620
commit 7f16feaff6
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
3 changed files with 13 additions and 7 deletions

View file

@ -49,14 +49,14 @@ module Invidious::Database::Users
PG_DB.exec(request, user.watched, user.email)
end
def mark_watched(user : User, vid : String)
def mark_watched(user : User, history_details : JSON::Any)
request = <<-SQL
UPDATE users
SET watched = array_append(array_remove(watched, $1), $1)
SET watched = array_append(array_remove(watched, $1::jsonb), $1::jsonb)
WHERE email = $2
SQL
PG_DB.exec(request, vid, user.email)
PG_DB.exec(request, history_details, user.email)
end
def mark_unwatched(user : User, vid : String)

View file

@ -86,7 +86,7 @@ module Invidious::Routes::API::V1::Authenticated
return error_json(400, "Invalid video id.")
end
Invidious::Database::Users.mark_watched(user, id)
# Invidious::Database::Users.mark_watched(user, id)
env.response.status_code = 204
end

View file

@ -76,8 +76,14 @@ module Invidious::Routes::Watch
end
env.params.query.delete_all("iv_load_policy")
history_details = JSON::Any.new({
"id" => JSON::Any.new(id),
"title" => JSON::Any.new(video.title),
"author" => JSON::Any.new(video.author)
})
if watched && preferences.watch_history
Invidious::Database::Users.mark_watched(user.as(User), id)
Invidious::Database::Users.mark_watched(user.as(User), history_details)
end
if CONFIG.enable_user_notifications && notifications && notifications.includes? id
@ -286,9 +292,9 @@ module Invidious::Routes::Watch
case action
when "action_mark_watched"
Invidious::Database::Users.mark_watched(user, id)
# Invidious::Database::Users.mark_watched(user, history_details)
when "action_mark_unwatched"
Invidious::Database::Users.mark_unwatched(user, id)
# Invidious::Database::Users.mark_unwatched(user, id)
else
return error_json(400, "Unsupported action #{action}")
end