From 40073e7089efb532417ac072297a8fae45706ffc Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 21 Feb 2019 13:26:36 -0600 Subject: [PATCH] Fix sorting options for /feed/private --- src/invidious.cr | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 19b924c2..e7fa4c90 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -2053,26 +2053,30 @@ get "/feed/private" do |env| latest_only ||= 0 latest_only = latest_only == 1 - if user.preferences.sort == "published - reverse" - sort = "" + sort = env.params.query["sort"]? + sort ||= "published" + + if sort == "published - reverse" + desc = "" else - sort = "DESC" + desc = "DESC" end view_name = "subscriptions_#{sha256(user.email)[0..7]}" if latest_only - videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} ORDER BY ucid, published #{sort}", as: ChannelVideo) + videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} \ + ORDER BY ucid, published", as: ChannelVideo) + videos.sort_by! { |video| video.published }.reverse! else videos = PG_DB.query_all("SELECT * FROM #{view_name} \ - ORDER BY published #{sort} LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo) + ORDER BY published #{desc} LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo) end - sort = env.params.query["sort"]? - sort ||= "published" - case sort + when "reverse_published" + videos.sort_by! { |video| video.published } when "alphabetically" videos.sort_by! { |video| video.title } when "reverse_alphabetically"