diff --git a/src/invidious.cr b/src/invidious.cr index d0ef43c1..34cf318b 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1438,6 +1438,12 @@ get "/subscription_ajax" do |env| user = env.get? "user" referer = get_referer(env) + redirect = env.params.query["redirect"]? + redirect ||= "false" + redirect = redirect == "true" + + count_text = "" + if user user = user.as(User) @@ -1500,9 +1506,18 @@ get "/subscription_ajax" do |env| PG_DB.exec("UPDATE users SET subscriptions = array_remove(subscriptions,$1) WHERE id = $2", channel_id, sid) end end + + count_text = PG_DB.query_one?("SELECT cardinality(subscriptions) FROM users WHERE id = $1", [sid], as: Int64) + count_text ||= 0 + count_text = "#{number_with_separator(count_text)} subscriptions" end - env.redirect referer + if redirect + env.redirect referer + else + env.response.content_type = "application/json" + {"countText" => count_text}.to_json + end end get "/delete_account" do |env| diff --git a/src/invidious/views/subscription_manager.ecr b/src/invidious/views/subscription_manager.ecr index b942e686..d420fbf8 100644 --- a/src/invidious/views/subscription_manager.ecr +++ b/src/invidious/views/subscription_manager.ecr @@ -4,7 +4,7 @@