From cdd916f51d68e9982ab3e98cad20c998504146cb Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Wed, 21 Nov 2018 13:35:37 -0600 Subject: [PATCH] Add async for manage_subscriptions --- src/invidious.cr | 17 +++++++++- src/invidious/views/subscription_manager.ecr | 33 ++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index d0ef43c10..34cf318b0 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 b942e686c..d420fbf8e 100644 --- a/src/invidious/views/subscription_manager.ecr +++ b/src/invidious/views/subscription_manager.ecr @@ -4,7 +4,7 @@
-

<%= subscriptions.size %> subscriptions

+

<%= subscriptions.size %> subscriptions

@@ -24,7 +24,12 @@

@@ -34,3 +39,27 @@ <% end %>
<% end %> + + \ No newline at end of file