|
|
@ -1817,6 +1817,10 @@ post "/preferences" do |env|
|
|
|
|
unseen_only ||= "off"
|
|
|
|
unseen_only ||= "off"
|
|
|
|
unseen_only = unseen_only == "on"
|
|
|
|
unseen_only = unseen_only == "on"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notifications_only = env.params.body["notifications_only"]?.try &.as(String)
|
|
|
|
|
|
|
|
notifications_only ||= "off"
|
|
|
|
|
|
|
|
notifications_only = notifications_only == "on"
|
|
|
|
|
|
|
|
|
|
|
|
preferences = {
|
|
|
|
preferences = {
|
|
|
|
"video_loop" => video_loop,
|
|
|
|
"video_loop" => video_loop,
|
|
|
|
"autoplay" => autoplay,
|
|
|
|
"autoplay" => autoplay,
|
|
|
@ -1831,6 +1835,7 @@ post "/preferences" do |env|
|
|
|
|
"sort" => sort,
|
|
|
|
"sort" => sort,
|
|
|
|
"latest_only" => latest_only,
|
|
|
|
"latest_only" => latest_only,
|
|
|
|
"unseen_only" => unseen_only,
|
|
|
|
"unseen_only" => unseen_only,
|
|
|
|
|
|
|
|
"notifications_only" => notifications_only,
|
|
|
|
}.to_json
|
|
|
|
}.to_json
|
|
|
|
|
|
|
|
|
|
|
|
PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences, user.email)
|
|
|
|
PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences, user.email)
|
|
|
@ -1871,6 +1876,28 @@ get "/feed/subscriptions" do |env|
|
|
|
|
offset = (page - 1) * max_results
|
|
|
|
offset = (page - 1) * max_results
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notifications = PG_DB.query_one("SELECT notifications FROM users WHERE email = $1", user.email,
|
|
|
|
|
|
|
|
as: Array(String))
|
|
|
|
|
|
|
|
if preferences.notifications_only && !notifications.empty?
|
|
|
|
|
|
|
|
args = arg_array(notifications)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
videos = PG_DB.query_all("SELECT * FROM channel_videos WHERE id IN (#{args})
|
|
|
|
|
|
|
|
ORDER BY published DESC", notifications, as: ChannelVideo)
|
|
|
|
|
|
|
|
notifications = [] of ChannelVideo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
videos.sort_by! { |video| video.published }.reverse!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case preferences.sort
|
|
|
|
|
|
|
|
when "alphabetically"
|
|
|
|
|
|
|
|
videos.sort_by! { |video| video.title }
|
|
|
|
|
|
|
|
when "alphabetically - reverse"
|
|
|
|
|
|
|
|
videos.sort_by! { |video| video.title }.reverse!
|
|
|
|
|
|
|
|
when "channel name"
|
|
|
|
|
|
|
|
videos.sort_by! { |video| video.author }
|
|
|
|
|
|
|
|
when "channel name - reverse"
|
|
|
|
|
|
|
|
videos.sort_by! { |video| video.author }.reverse!
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
if preferences.latest_only
|
|
|
|
if preferences.latest_only
|
|
|
|
if preferences.unseen_only
|
|
|
|
if preferences.unseen_only
|
|
|
|
ucids = arg_array(user.subscriptions)
|
|
|
|
ucids = arg_array(user.subscriptions)
|
|
|
@ -1926,6 +1953,7 @@ get "/feed/subscriptions" do |env|
|
|
|
|
|
|
|
|
|
|
|
|
notifications = videos.select { |v| notifications.includes? v.id }
|
|
|
|
notifications = videos.select { |v| notifications.includes? v.id }
|
|
|
|
videos = videos - notifications
|
|
|
|
videos = videos - notifications
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if !limit
|
|
|
|
if !limit
|
|
|
|
videos = videos[0..max_results]
|
|
|
|
videos = videos[0..max_results]
|
|
|
|