From fdcfe0bb14dd7f95eb3ebaf9f8da22159940580e Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Mon, 7 May 2018 21:57:47 -0500 Subject: [PATCH] Seperate new videos in subscription feed --- src/helpers.cr | 2 +- src/invidious.cr | 5 +++++ src/views/subscriptions.ecr | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/helpers.cr b/src/helpers.cr index 8026f472..0ab2ea46 100644 --- a/src/helpers.cr +++ b/src/helpers.cr @@ -605,7 +605,7 @@ def get_user(sid, client, headers, db) args = arg_array(user_array) db.exec("INSERT INTO users VALUES (#{args}) \ - ON CONFLICT (email) DO UPDATE SET id = $1, updated = $2, notifications = $3, subscriptions = $4", user_array) + ON CONFLICT (email) DO UPDATE SET id = $1, updated = $2, subscriptions = $4", user_array) end else user = fetch_user(sid, client, headers) diff --git a/src/invidious.cr b/src/invidious.cr index 7af339ed..afa69dd5 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -729,6 +729,11 @@ get "/feed/subscriptions" do |env| 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) + 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 } + vidoes = videos - notifications + if !limit videos = videos[0..max_results] end diff --git a/src/views/subscriptions.ecr b/src/views/subscriptions.ecr index 98e6a18c..7c6f722d 100644 --- a/src/views/subscriptions.ecr +++ b/src/views/subscriptions.ecr @@ -2,6 +2,30 @@ Subscriptions - Invidious <% end %> +<% if !notifications.empty? %> +<% notifications.each_slice(4) do |slice| %> +
+ <% slice.each do |video| %> +
+
+ + +

<%= video.title %>

+
+

+ <%= video.author %> +

+

+

Shared <%= video.published.to_s("%B %-d, %Y at %r") %>
+

+
+
+ <% end %> +
+<% end %> +
+<% end %> + <% videos.each_slice(4) do |slice| %>
<% slice.each do |video| %>