Compare commits

...

1 Commits

Author SHA1 Message Date
Émilien Devos
72f03cd9de add ability to disable notifications 2022-02-25 09:42:55 +00:00
9 changed files with 29 additions and 6 deletions

View File

@ -66,6 +66,7 @@
"preferences_listen_label": "Listen by default: ", "preferences_listen_label": "Listen by default: ",
"preferences_local_label": "Proxy videos: ", "preferences_local_label": "Proxy videos: ",
"preferences_watch_history_label": "Enable watch history: ", "preferences_watch_history_label": "Enable watch history: ",
"preferences_notifications_label": "Enable notifications: ",
"preferences_speed_label": "Default speed: ", "preferences_speed_label": "Default speed: ",
"preferences_quality_label": "Preferred video quality: ", "preferences_quality_label": "Preferred video quality: ",
"preferences_quality_option_dash": "DASH (adaptative quality)", "preferences_quality_option_dash": "DASH (adaptative quality)",

View File

@ -226,7 +226,7 @@ def fetch_channel(ucid, pull_all_videos : Bool)
# meaning the above timestamp is always null # meaning the above timestamp is always null
was_insert = Invidious::Database::ChannelVideos.insert(video) was_insert = Invidious::Database::ChannelVideos.insert(video)
if was_insert if preferences.notifications && was_insert
LOGGER.trace("fetch_channel: #{ucid} : video #{video_id} : Inserted, updating subscriptions") LOGGER.trace("fetch_channel: #{ucid} : video #{video_id} : Inserted, updating subscriptions")
Invidious::Database::Users.add_notification(video) Invidious::Database::Users.add_notification(video)
else else
@ -264,7 +264,9 @@ def fetch_channel(ucid, pull_all_videos : Bool)
# so since they don't provide a published date here we can safely ignore them. # so since they don't provide a published date here we can safely ignore them.
if Time.utc - video.published > 1.minute if Time.utc - video.published > 1.minute
was_insert = Invidious::Database::ChannelVideos.insert(video) was_insert = Invidious::Database::ChannelVideos.insert(video)
Invidious::Database::Users.add_notification(video) if was_insert if preferences.notifications && was_insert
Invidious::Database::Users.add_notification(video)
end
end end
end end

View File

@ -24,6 +24,7 @@ struct ConfigPreferences
property local : Bool = false property local : Bool = false
property locale : String = "en-US" property locale : String = "en-US"
property watch_history : Bool = true property watch_history : Bool = true
property notifications : Bool = true
property max_results : Int32 = 40 property max_results : Int32 = 40
property notifications_only : Bool = false property notifications_only : Bool = false
property player_style : String = "invidious" property player_style : String = "invidious"

View File

@ -134,7 +134,9 @@ module Invidious::Routes::Embed
# end # end
if notifications && notifications.includes? id if notifications && notifications.includes? id
Invidious::Database::Users.remove_notification(user.as(User), id) if preferences.notifications
Invidious::Database::Users.remove_notification(user.as(User), id)
end
env.get("user").as(User).notifications.delete(id) env.get("user").as(User).notifications.delete(id)
notifications.delete(id) notifications.delete(id)
end end

View File

@ -100,7 +100,9 @@ module Invidious::Routes::Feeds
# we know a user has looked at their feed e.g. in the past 10 minutes, # we know a user has looked at their feed e.g. in the past 10 minutes,
# they've already seen a video posted 20 minutes ago, and don't need # they've already seen a video posted 20 minutes ago, and don't need
# to be notified. # to be notified.
Invidious::Database::Users.clear_notifications(user) if preferences.notifications
Invidious::Database::Users.clear_notifications(user)
end
user.notifications = [] of String user.notifications = [] of String
env.set "user", user env.set "user", user
@ -417,7 +419,9 @@ module Invidious::Routes::Feeds
}) })
was_insert = Invidious::Database::ChannelVideos.insert(video, with_premiere_timestamp: true) was_insert = Invidious::Database::ChannelVideos.insert(video, with_premiere_timestamp: true)
Invidious::Database::Users.add_notification(video) if was_insert if preferences.notifications && was_insert
Invidious::Database::Users.add_notification(video)
end
end end
end end

View File

@ -51,6 +51,10 @@ module Invidious::Routes::PreferencesRoute
watch_history ||= "off" watch_history ||= "off"
watch_history = watch_history == "on" watch_history = watch_history == "on"
notifications = env.params.body["notifications"]?.try &.as(String)
notifications ||= "off"
notifications = notifications == "on"
speed = env.params.body["speed"]?.try &.as(String).to_f32? speed = env.params.body["speed"]?.try &.as(String).to_f32?
speed ||= CONFIG.default_user_preferences.speed speed ||= CONFIG.default_user_preferences.speed
@ -154,6 +158,7 @@ module Invidious::Routes::PreferencesRoute
listen: listen, listen: listen,
local: local, local: local,
watch_history: watch_history, watch_history: watch_history,
notifications: notifications,
locale: locale, locale: locale,
max_results: max_results, max_results: max_results,
notifications_only: notifications_only, notifications_only: notifications_only,

View File

@ -80,7 +80,9 @@ module Invidious::Routes::Watch
end end
if notifications && notifications.includes? id if notifications && notifications.includes? id
Invidious::Database::Users.remove_notification(user.as(User), id) if preferences.notifications
Invidious::Database::Users.remove_notification(user.as(User), id)
end
env.get("user").as(User).notifications.delete(id) env.get("user").as(User).notifications.delete(id)
notifications.delete(id) notifications.delete(id)
end end

View File

@ -24,6 +24,7 @@ struct Preferences
property listen : Bool = CONFIG.default_user_preferences.listen property listen : Bool = CONFIG.default_user_preferences.listen
property local : Bool = CONFIG.default_user_preferences.local property local : Bool = CONFIG.default_user_preferences.local
property watch_history : Bool = CONFIG.default_user_preferences.watch_history property watch_history : Bool = CONFIG.default_user_preferences.watch_history
property notifications : Bool = CONFIG.default_user_preferences.notifications
property vr_mode : Bool = CONFIG.default_user_preferences.vr_mode property vr_mode : Bool = CONFIG.default_user_preferences.vr_mode
property show_nick : Bool = CONFIG.default_user_preferences.show_nick property show_nick : Bool = CONFIG.default_user_preferences.show_nick

View File

@ -206,6 +206,11 @@
<% if env.get? "user" %> <% if env.get? "user" %>
<legend><%= translate(locale, "preferences_category_subscription") %></legend> <legend><%= translate(locale, "preferences_category_subscription") %></legend>
<div class="pure-control-group">
<label for="notifications"><%= translate(locale, "preferences_notifications_label") %></label>
<input name="notifications" id="notifications" type="checkbox" <% if preferences.notifications %>checked<% end %>>
</div>
<div class="pure-control-group"> <div class="pure-control-group">
<label for="watch_history"><%= translate(locale, "preferences_watch_history_label") %></label> <label for="watch_history"><%= translate(locale, "preferences_watch_history_label") %></label>
<input name="watch_history" id="watch_history" type="checkbox" <% if preferences.watch_history %>checked<% end %>> <input name="watch_history" id="watch_history" type="checkbox" <% if preferences.watch_history %>checked<% end %>>