aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉmilien Devos <contact@emiliendevos.be>2022-02-25 09:30:24 +0000
committerGitHub <noreply@github.com>2022-02-25 09:42:55 +0000
commit72f03cd9de776ecb9832140c8fef3ed8fca18402 (patch)
tree86489f7cce84304ce115e9f97630e7cdc8cf9b82
parent7f445f61670c2415d54f663184e4fa84a8289f15 (diff)
add ability to disable notificationsdisable-notifications
-rw-r--r--locales/en-US.json1
-rw-r--r--src/invidious/channels/channels.cr6
-rw-r--r--src/invidious/config.cr1
-rw-r--r--src/invidious/routes/embed.cr4
-rw-r--r--src/invidious/routes/feeds.cr8
-rw-r--r--src/invidious/routes/preferences.cr5
-rw-r--r--src/invidious/routes/watch.cr4
-rw-r--r--src/invidious/user/preferences.cr1
-rw-r--r--src/invidious/views/user/preferences.ecr5
9 files changed, 29 insertions, 6 deletions
diff --git a/locales/en-US.json b/locales/en-US.json
index 1335d384..63db7c24 100644
--- a/locales/en-US.json
+++ b/locales/en-US.json
@@ -66,6 +66,7 @@
66 "preferences_listen_label": "Listen by default: ", 66 "preferences_listen_label": "Listen by default: ",
67 "preferences_local_label": "Proxy videos: ", 67 "preferences_local_label": "Proxy videos: ",
68 "preferences_watch_history_label": "Enable watch history: ", 68 "preferences_watch_history_label": "Enable watch history: ",
69 "preferences_notifications_label": "Enable notifications: ",
69 "preferences_speed_label": "Default speed: ", 70 "preferences_speed_label": "Default speed: ",
70 "preferences_quality_label": "Preferred video quality: ", 71 "preferences_quality_label": "Preferred video quality: ",
71 "preferences_quality_option_dash": "DASH (adaptative quality)", 72 "preferences_quality_option_dash": "DASH (adaptative quality)",
diff --git a/src/invidious/channels/channels.cr b/src/invidious/channels/channels.cr
index e0459cc3..54634534 100644
--- a/src/invidious/channels/channels.cr
+++ b/src/invidious/channels/channels.cr
@@ -226,7 +226,7 @@ def fetch_channel(ucid, pull_all_videos : Bool)
226 # meaning the above timestamp is always null 226 # meaning the above timestamp is always null
227 was_insert = Invidious::Database::ChannelVideos.insert(video) 227 was_insert = Invidious::Database::ChannelVideos.insert(video)
228 228
229 if was_insert 229 if preferences.notifications && was_insert
230 LOGGER.trace("fetch_channel: #{ucid} : video #{video_id} : Inserted, updating subscriptions") 230 LOGGER.trace("fetch_channel: #{ucid} : video #{video_id} : Inserted, updating subscriptions")
231 Invidious::Database::Users.add_notification(video) 231 Invidious::Database::Users.add_notification(video)
232 else 232 else
@@ -264,7 +264,9 @@ def fetch_channel(ucid, pull_all_videos : Bool)
264 # so since they don't provide a published date here we can safely ignore them. 264 # so since they don't provide a published date here we can safely ignore them.
265 if Time.utc - video.published > 1.minute 265 if Time.utc - video.published > 1.minute
266 was_insert = Invidious::Database::ChannelVideos.insert(video) 266 was_insert = Invidious::Database::ChannelVideos.insert(video)
267 Invidious::Database::Users.add_notification(video) if was_insert 267 if preferences.notifications && was_insert
268 Invidious::Database::Users.add_notification(video)
269 end
268 end 270 end
269 end 271 end
270 272
diff --git a/src/invidious/config.cr b/src/invidious/config.cr
index 93c4c0f7..ff959300 100644
--- a/src/invidious/config.cr
+++ b/src/invidious/config.cr
@@ -24,6 +24,7 @@ struct ConfigPreferences
24 property local : Bool = false 24 property local : Bool = false
25 property locale : String = "en-US" 25 property locale : String = "en-US"
26 property watch_history : Bool = true 26 property watch_history : Bool = true
27 property notifications : Bool = true
27 property max_results : Int32 = 40 28 property max_results : Int32 = 40
28 property notifications_only : Bool = false 29 property notifications_only : Bool = false
29 property player_style : String = "invidious" 30 property player_style : String = "invidious"
diff --git a/src/invidious/routes/embed.cr b/src/invidious/routes/embed.cr
index 207970b0..72617a63 100644
--- a/src/invidious/routes/embed.cr
+++ b/src/invidious/routes/embed.cr
@@ -134,7 +134,9 @@ module Invidious::Routes::Embed
134 # end 134 # end
135 135
136 if notifications && notifications.includes? id 136 if notifications && notifications.includes? id
137 Invidious::Database::Users.remove_notification(user.as(User), id) 137 if preferences.notifications
138 Invidious::Database::Users.remove_notification(user.as(User), id)
139 end
138 env.get("user").as(User).notifications.delete(id) 140 env.get("user").as(User).notifications.delete(id)
139 notifications.delete(id) 141 notifications.delete(id)
140 end 142 end
diff --git a/src/invidious/routes/feeds.cr b/src/invidious/routes/feeds.cr
index f7f7b426..e0d69fcd 100644
--- a/src/invidious/routes/feeds.cr
+++ b/src/invidious/routes/feeds.cr
@@ -100,7 +100,9 @@ module Invidious::Routes::Feeds
100 # we know a user has looked at their feed e.g. in the past 10 minutes, 100 # we know a user has looked at their feed e.g. in the past 10 minutes,
101 # they've already seen a video posted 20 minutes ago, and don't need 101 # they've already seen a video posted 20 minutes ago, and don't need
102 # to be notified. 102 # to be notified.
103 Invidious::Database::Users.clear_notifications(user) 103 if preferences.notifications
104 Invidious::Database::Users.clear_notifications(user)
105 end
104 user.notifications = [] of String 106 user.notifications = [] of String
105 env.set "user", user 107 env.set "user", user
106 108
@@ -417,7 +419,9 @@ module Invidious::Routes::Feeds
417 }) 419 })
418 420
419 was_insert = Invidious::Database::ChannelVideos.insert(video, with_premiere_timestamp: true) 421 was_insert = Invidious::Database::ChannelVideos.insert(video, with_premiere_timestamp: true)
420 Invidious::Database::Users.add_notification(video) if was_insert 422 if preferences.notifications && was_insert
423 Invidious::Database::Users.add_notification(video)
424 end
421 end 425 end
422 end 426 end
423 427
diff --git a/src/invidious/routes/preferences.cr b/src/invidious/routes/preferences.cr
index 570cba69..238c1bfa 100644
--- a/src/invidious/routes/preferences.cr
+++ b/src/invidious/routes/preferences.cr
@@ -51,6 +51,10 @@ module Invidious::Routes::PreferencesRoute
51 watch_history ||= "off" 51 watch_history ||= "off"
52 watch_history = watch_history == "on" 52 watch_history = watch_history == "on"
53 53
54 notifications = env.params.body["notifications"]?.try &.as(String)
55 notifications ||= "off"
56 notifications = notifications == "on"
57
54 speed = env.params.body["speed"]?.try &.as(String).to_f32? 58 speed = env.params.body["speed"]?.try &.as(String).to_f32?
55 speed ||= CONFIG.default_user_preferences.speed 59 speed ||= CONFIG.default_user_preferences.speed
56 60
@@ -154,6 +158,7 @@ module Invidious::Routes::PreferencesRoute
154 listen: listen, 158 listen: listen,
155 local: local, 159 local: local,
156 watch_history: watch_history, 160 watch_history: watch_history,
161 notifications: notifications,
157 locale: locale, 162 locale: locale,
158 max_results: max_results, 163 max_results: max_results,
159 notifications_only: notifications_only, 164 notifications_only: notifications_only,
diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr
index 867ffa6a..99703297 100644
--- a/src/invidious/routes/watch.cr
+++ b/src/invidious/routes/watch.cr
@@ -80,7 +80,9 @@ module Invidious::Routes::Watch
80 end 80 end
81 81
82 if notifications && notifications.includes? id 82 if notifications && notifications.includes? id
83 Invidious::Database::Users.remove_notification(user.as(User), id) 83 if preferences.notifications
84 Invidious::Database::Users.remove_notification(user.as(User), id)
85 end
84 env.get("user").as(User).notifications.delete(id) 86 env.get("user").as(User).notifications.delete(id)
85 notifications.delete(id) 87 notifications.delete(id)
86 end 88 end
diff --git a/src/invidious/user/preferences.cr b/src/invidious/user/preferences.cr
index b3059403..6490aa7b 100644
--- a/src/invidious/user/preferences.cr
+++ b/src/invidious/user/preferences.cr
@@ -24,6 +24,7 @@ struct Preferences
24 property listen : Bool = CONFIG.default_user_preferences.listen 24 property listen : Bool = CONFIG.default_user_preferences.listen
25 property local : Bool = CONFIG.default_user_preferences.local 25 property local : Bool = CONFIG.default_user_preferences.local
26 property watch_history : Bool = CONFIG.default_user_preferences.watch_history 26 property watch_history : Bool = CONFIG.default_user_preferences.watch_history
27 property notifications : Bool = CONFIG.default_user_preferences.notifications
27 property vr_mode : Bool = CONFIG.default_user_preferences.vr_mode 28 property vr_mode : Bool = CONFIG.default_user_preferences.vr_mode
28 property show_nick : Bool = CONFIG.default_user_preferences.show_nick 29 property show_nick : Bool = CONFIG.default_user_preferences.show_nick
29 30
diff --git a/src/invidious/views/user/preferences.ecr b/src/invidious/views/user/preferences.ecr
index dbb5e9db..7c269821 100644
--- a/src/invidious/views/user/preferences.ecr
+++ b/src/invidious/views/user/preferences.ecr
@@ -207,6 +207,11 @@
207 <legend><%= translate(locale, "preferences_category_subscription") %></legend> 207 <legend><%= translate(locale, "preferences_category_subscription") %></legend>
208 208
209 <div class="pure-control-group"> 209 <div class="pure-control-group">
210 <label for="notifications"><%= translate(locale, "preferences_notifications_label") %></label>
211 <input name="notifications" id="notifications" type="checkbox" <% if preferences.notifications %>checked<% end %>>
212 </div>
213
214 <div class="pure-control-group">
210 <label for="watch_history"><%= translate(locale, "preferences_watch_history_label") %></label> 215 <label for="watch_history"><%= translate(locale, "preferences_watch_history_label") %></label>
211 <input name="watch_history" id="watch_history" type="checkbox" <% if preferences.watch_history %>checked<% end %>> 216 <input name="watch_history" id="watch_history" type="checkbox" <% if preferences.watch_history %>checked<% end %>>
212 </div> 217 </div>