mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-12-15 17:45:10 +00:00
feat: add experimental support to hide channels from the popular page
This commit is contained in:
@@ -53,6 +53,8 @@ struct ConfigPreferences
|
||||
property show_nick : Bool = true
|
||||
property save_player_pos : Bool = false
|
||||
property enable_dearrow : Bool = false
|
||||
@[YAML::Field(ignore: true)]
|
||||
property hidden_channels : Array(String)? = nil
|
||||
|
||||
def to_tuple
|
||||
{% begin %}
|
||||
|
||||
@@ -35,6 +35,7 @@ module Invidious::Routes::Feeds
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
|
||||
if CONFIG.popular_enabled
|
||||
preferences = env.get("preferences").as(Preferences)
|
||||
templated "feeds/popular"
|
||||
else
|
||||
message = translate(locale, "The Popular feed has been disabled by the administrator.")
|
||||
|
||||
@@ -144,6 +144,30 @@ module Invidious::Routes::PreferencesRoute
|
||||
notifications_only ||= "off"
|
||||
notifications_only = notifications_only == "on"
|
||||
|
||||
hidden_channels = env.params.body["hidden_channels"]?.try &.as(String)
|
||||
if hidden_channels
|
||||
hidden_channels = hidden_channels.split("\n")
|
||||
|
||||
delete = [] of Int32
|
||||
hidden_channels.each_with_index do |ucid, idx|
|
||||
u = ucid.rstrip("\r")
|
||||
|
||||
if (u == "") || (u == "\r")
|
||||
delete << idx
|
||||
next
|
||||
end
|
||||
|
||||
# 24 is the length of channel UCIDs
|
||||
if u.size != 24
|
||||
raise InfoException.new("Channel ID has to be 25 characters long!")
|
||||
else
|
||||
hidden_channels[idx] = u
|
||||
end
|
||||
end
|
||||
|
||||
delete.reverse_each { |i| hidden_channels.delete_at(i) }
|
||||
end
|
||||
|
||||
# Convert to JSON and back again to take advantage of converters used for compatibility
|
||||
preferences = Preferences.from_json({
|
||||
annotations: annotations,
|
||||
@@ -180,6 +204,7 @@ module Invidious::Routes::PreferencesRoute
|
||||
vr_mode: vr_mode,
|
||||
show_nick: show_nick,
|
||||
save_player_pos: save_player_pos,
|
||||
hidden_channels: hidden_channels,
|
||||
}.to_json)
|
||||
|
||||
if user = env.get? "user"
|
||||
|
||||
@@ -56,6 +56,7 @@ struct Preferences
|
||||
property extend_desc : Bool = CONFIG.default_user_preferences.extend_desc
|
||||
property volume : Int32 = CONFIG.default_user_preferences.volume
|
||||
property save_player_pos : Bool = CONFIG.default_user_preferences.save_player_pos
|
||||
property hidden_channels : Array(String)? = nil
|
||||
|
||||
module BoolToString
|
||||
def self.to_json(value : String, json : JSON::Builder)
|
||||
|
||||
@@ -13,6 +13,11 @@
|
||||
|
||||
<div class="pure-g">
|
||||
<% popular_videos.each do |item| %>
|
||||
<%
|
||||
if hidden_channels = preferences.hidden_channels
|
||||
next if hidden_channels.any? { |ucid| ucid == item.ucid }
|
||||
end
|
||||
%>
|
||||
<%= rendered "components/item" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -211,6 +211,13 @@
|
||||
<input name="automatic_instance_redirect" id="automatic_instance_redirect" type="checkbox" <% if preferences.automatic_instance_redirect %>checked<% end %>>
|
||||
</div>
|
||||
|
||||
<div class="pure-control-group">
|
||||
<label for="hidden_channels"><%= translate(locale, "preferences_hidden_channels") %></label>
|
||||
<% hidden_channels = preferences.hidden_channels %>
|
||||
<textarea name="hidden_channels" id="hidden_channels" class="hidden-channels"><%= hidden_channels[0...].join("\n") if hidden_channels %></textarea>
|
||||
<label for="hidden_channels"><%= translate(locale, "preferences_hidden_channels_label") %></label>
|
||||
</div>
|
||||
|
||||
<% if env.get? "user" %>
|
||||
<legend><%= translate(locale, "preferences_category_subscription") %></legend>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user