mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-03-16.git
synced 2024-08-15 00:53:18 +00:00
Add 'published - reverse' option to feed
This commit is contained in:
parent
c8b321920d
commit
adcefa4ffa
2 changed files with 20 additions and 8 deletions
|
@ -1541,6 +1541,12 @@ get "/feed/subscriptions" do |env|
|
||||||
offset = (page - 1) * max_results
|
offset = (page - 1) * max_results
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if preferences.sort == "published - reverse"
|
||||||
|
sort = ""
|
||||||
|
else
|
||||||
|
sort = "DESC"
|
||||||
|
end
|
||||||
|
|
||||||
notifications = PG_DB.query_one("SELECT notifications FROM users WHERE email = $1", user.email,
|
notifications = PG_DB.query_one("SELECT notifications FROM users WHERE email = $1", user.email,
|
||||||
as: Array(String))
|
as: Array(String))
|
||||||
view_name = "subscriptions_#{sha256(user.email)[0..7]}"
|
view_name = "subscriptions_#{sha256(user.email)[0..7]}"
|
||||||
|
@ -1549,7 +1555,7 @@ get "/feed/subscriptions" do |env|
|
||||||
args = arg_array(notifications)
|
args = arg_array(notifications)
|
||||||
|
|
||||||
notifications = PG_DB.query_all("SELECT * FROM channel_videos WHERE id IN (#{args})
|
notifications = PG_DB.query_all("SELECT * FROM channel_videos WHERE id IN (#{args})
|
||||||
ORDER BY published DESC", notifications, as: ChannelVideo)
|
ORDER BY published #{sort}", notifications, as: ChannelVideo)
|
||||||
videos = [] of ChannelVideo
|
videos = [] of ChannelVideo
|
||||||
|
|
||||||
notifications.sort_by! { |video| video.published }.reverse!
|
notifications.sort_by! { |video| video.published }.reverse!
|
||||||
|
@ -1574,11 +1580,11 @@ get "/feed/subscriptions" do |env|
|
||||||
end
|
end
|
||||||
|
|
||||||
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} WHERE \
|
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} WHERE \
|
||||||
id NOT IN (#{watched}) ORDER BY ucid, published DESC",
|
id NOT IN (#{watched}) ORDER BY published, ucid #{sort}",
|
||||||
user.watched, as: ChannelVideo)
|
user.watched, as: ChannelVideo)
|
||||||
else
|
else
|
||||||
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} \
|
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} \
|
||||||
ORDER BY ucid, published DESC", as: ChannelVideo)
|
ORDER BY published, ucid #{sort}", as: ChannelVideo)
|
||||||
end
|
end
|
||||||
|
|
||||||
videos.sort_by! { |video| video.published }.reverse!
|
videos.sort_by! { |video| video.published }.reverse!
|
||||||
|
@ -1591,11 +1597,11 @@ get "/feed/subscriptions" do |env|
|
||||||
end
|
end
|
||||||
|
|
||||||
videos = PG_DB.query_all("SELECT * FROM #{view_name} WHERE \
|
videos = PG_DB.query_all("SELECT * FROM #{view_name} WHERE \
|
||||||
id NOT IN (#{watched}) LIMIT $1 OFFSET $2",
|
id NOT IN (#{watched}) ORDER BY published #{sort} LIMIT $1 OFFSET $2",
|
||||||
[limit, offset] + user.watched, as: ChannelVideo)
|
[limit, offset] + user.watched, as: ChannelVideo)
|
||||||
else
|
else
|
||||||
videos = PG_DB.query_all("SELECT * FROM #{view_name} \
|
videos = PG_DB.query_all("SELECT * FROM #{view_name} \
|
||||||
ORDER BY published DESC LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo)
|
ORDER BY published #{sort} LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1746,14 +1752,20 @@ get "/feed/private" do |env|
|
||||||
latest_only ||= 0
|
latest_only ||= 0
|
||||||
latest_only = latest_only == 1
|
latest_only = latest_only == 1
|
||||||
|
|
||||||
|
if user.preferences.sort == "published - reverse"
|
||||||
|
sort = ""
|
||||||
|
else
|
||||||
|
sort = "DESC"
|
||||||
|
end
|
||||||
|
|
||||||
view_name = "subscriptions_#{sha256(user.email)[0..7]}"
|
view_name = "subscriptions_#{sha256(user.email)[0..7]}"
|
||||||
|
|
||||||
if latest_only
|
if latest_only
|
||||||
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} ORDER BY ucid, published DESC", as: ChannelVideo)
|
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} ORDER BY ucid, published #{sort}", as: ChannelVideo)
|
||||||
videos.sort_by! { |video| video.published }.reverse!
|
videos.sort_by! { |video| video.published }.reverse!
|
||||||
else
|
else
|
||||||
videos = PG_DB.query_all("SELECT * FROM #{view_name} \
|
videos = PG_DB.query_all("SELECT * FROM #{view_name} \
|
||||||
ORDER BY published DESC LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo)
|
ORDER BY published #{sort} LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo)
|
||||||
end
|
end
|
||||||
|
|
||||||
sort = env.params.query["sort"]?
|
sort = env.params.query["sort"]?
|
||||||
|
|
|
@ -131,7 +131,7 @@ function update_value(element) {
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="sort">Sort videos by: </label>
|
<label for="sort">Sort videos by: </label>
|
||||||
<select name="sort" id="sort">
|
<select name="sort" id="sort">
|
||||||
<% ["published", "alphabetically", "alphabetically - reverse", "channel name", "channel name - reverse"].each do |option| %>
|
<% {"published", "published - reverse", "alphabetically", "alphabetically - reverse", "channel name", "channel name - reverse"}.each do |option| %>
|
||||||
<option <% if user.preferences.sort == option %> selected <% end %>><%= option %></option>
|
<option <% if user.preferences.sort == option %> selected <% end %>><%= option %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
|
|
Loading…
Reference in a new issue