summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-07-31 21:34:57 -0500
committerGitHub <noreply@github.com>2018-07-31 21:34:57 -0500
commit51903462eff0b83b831464b5cc189230698a106f (patch)
tree94fb606776970849e521356e0bab6d24c013b449 /src
parentcdd644ded72152ea47babd617c265a1fc351a080 (diff)
parentb1b271354637a3172475cc9e04edc408ae50ee5e (diff)
downloadinvidious-51903462eff0b83b831464b5cc189230698a106f.tar.gz
invidious-51903462eff0b83b831464b5cc189230698a106f.tar.bz2
invidious-51903462eff0b83b831464b5cc189230698a106f.zip
Merge pull request #53 from omarroth/notifications-only
Add option to view only notifications
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr138
-rw-r--r--src/invidious/helpers.cr13
-rw-r--r--src/invidious/views/preferences.ecr5
3 files changed, 97 insertions, 59 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 4b18f681..f59dea36 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -1817,20 +1817,25 @@ post "/preferences" do |env|
unseen_only ||= "off"
unseen_only = unseen_only == "on"
+ notifications_only = env.params.body["notifications_only"]?.try &.as(String)
+ notifications_only ||= "off"
+ notifications_only = notifications_only == "on"
+
preferences = {
- "video_loop" => video_loop,
- "autoplay" => autoplay,
- "speed" => speed,
- "quality" => quality,
- "volume" => volume,
- "comments" => comments,
- "redirect_feed" => redirect_feed,
- "dark_mode" => dark_mode,
- "thin_mode" => thin_mode,
- "max_results" => max_results,
- "sort" => sort,
- "latest_only" => latest_only,
- "unseen_only" => unseen_only,
+ "video_loop" => video_loop,
+ "autoplay" => autoplay,
+ "speed" => speed,
+ "quality" => quality,
+ "volume" => volume,
+ "comments" => comments,
+ "redirect_feed" => redirect_feed,
+ "dark_mode" => dark_mode,
+ "thin_mode" => thin_mode,
+ "max_results" => max_results,
+ "sort" => sort,
+ "latest_only" => latest_only,
+ "unseen_only" => unseen_only,
+ "notifications_only" => notifications_only,
}.to_json
PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences, user.email)
@@ -1871,61 +1876,84 @@ get "/feed/subscriptions" do |env|
offset = (page - 1) * max_results
end
- if preferences.latest_only
- if preferences.unseen_only
- ucids = arg_array(user.subscriptions)
- if user.watched.empty?
- watched = "'{}'"
- else
- watched = arg_array(user.watched, user.subscriptions.size + 1)
- 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 DISTINCT ON (ucid) * FROM channel_videos WHERE \
- ucid IN (#{ucids}) AND id NOT IN (#{watched}) ORDER BY ucid, published DESC",
- user.subscriptions + user.watched, as: ChannelVideo)
- else
- args = arg_array(user.subscriptions)
- videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM channel_videos WHERE \
- ucid IN (#{args}) ORDER BY ucid, published DESC", user.subscriptions, as: ChannelVideo)
- end
+ 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.unseen_only
- ucids = arg_array(user.subscriptions, 3)
- if user.watched.empty?
- watched = "'{}'"
+ if preferences.latest_only
+ if preferences.unseen_only
+ ucids = arg_array(user.subscriptions)
+ if user.watched.empty?
+ watched = "'{}'"
+ else
+ watched = arg_array(user.watched, user.subscriptions.size + 1)
+ end
+
+ videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM channel_videos WHERE \
+ ucid IN (#{ucids}) AND id NOT IN (#{watched}) ORDER BY ucid, published DESC",
+ user.subscriptions + user.watched, as: ChannelVideo)
else
- watched = arg_array(user.watched, user.subscriptions.size + 3)
+ args = arg_array(user.subscriptions)
+ videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM channel_videos WHERE \
+ ucid IN (#{args}) ORDER BY ucid, published DESC", user.subscriptions, as: ChannelVideo)
end
- videos = PG_DB.query_all("SELECT * FROM channel_videos WHERE ucid IN (#{ucids}) \
- AND id NOT IN (#{watched}) ORDER BY published DESC LIMIT $1 OFFSET $2",
- [limit, offset] + user.subscriptions + user.watched, as: ChannelVideo)
+ videos.sort_by! { |video| video.published }.reverse!
else
- args = arg_array(user.subscriptions, 3)
- videos = PG_DB.query_all("SELECT * FROM channel_videos WHERE ucid IN (#{args}) \
+ if preferences.unseen_only
+ ucids = arg_array(user.subscriptions, 3)
+ if user.watched.empty?
+ watched = "'{}'"
+ else
+ watched = arg_array(user.watched, user.subscriptions.size + 3)
+ end
+
+ videos = PG_DB.query_all("SELECT * FROM channel_videos WHERE ucid IN (#{ucids}) \
+ AND id NOT IN (#{watched}) ORDER BY published DESC LIMIT $1 OFFSET $2",
+ [limit, offset] + user.subscriptions + user.watched, as: ChannelVideo)
+ else
+ args = arg_array(user.subscriptions, 3)
+ videos = PG_DB.query_all("SELECT * FROM channel_videos WHERE ucid IN (#{args}) \
ORDER BY published DESC LIMIT $1 OFFSET $2", [limit, offset] + user.subscriptions, as: ChannelVideo)
+ end
end
- end
- 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
+ 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
- # TODO: Add option to disable picking out notifications from regular feed
- notifications = PG_DB.query_one("SELECT notifications FROM users WHERE email = $1", user.email,
- as: Array(String))
+ # TODO: Add option to disable picking out notifications from regular feed
+ notifications = PG_DB.query_one("SELECT notifications FROM users WHERE email = $1", user.email,
+ as: Array(String))
- notifications = videos.select { |v| notifications.includes? v.id }
- videos = videos - notifications
+ notifications = videos.select { |v| notifications.includes? v.id }
+ videos = videos - notifications
+ end
if !limit
videos = videos[0..max_results]
diff --git a/src/invidious/helpers.cr b/src/invidious/helpers.cr
index 3cae652e..aa0939f1 100644
--- a/src/invidious/helpers.cr
+++ b/src/invidious/helpers.cr
@@ -176,10 +176,15 @@ class Preferences
nilable: true,
default: false,
},
- max_results: Int32,
- sort: String,
- latest_only: Bool,
- unseen_only: Bool,
+ max_results: Int32,
+ sort: String,
+ latest_only: Bool,
+ unseen_only: Bool,
+ notifications_only: {
+ type: Bool,
+ nilable: true,
+ default: false,
+ },
})
end
diff --git a/src/invidious/views/preferences.ecr b/src/invidious/views/preferences.ecr
index b60df558..31efce89 100644
--- a/src/invidious/views/preferences.ecr
+++ b/src/invidious/views/preferences.ecr
@@ -97,6 +97,11 @@ function update_value(element) {
<input name="unseen_only" id="unseen_only" type="checkbox" <% if user.preferences.unseen_only %>checked<% end %>>
</div>
+ <div class="pure-control-group">
+ <label for="notifications_only">Only show notifications: </label>
+ <input name="notifications_only" id="notifications_only" type="checkbox" <% if user.preferences.notifications_only %>checked<% end %>>
+ </div>
+
<legend>Data preferences</legend>
<div class="pure-control-group">
<label>