mirror of
https://github.com/iv-org/invidious.git
synced 2026-09-06 17:12:45 -05:00
feat: show "Comments are turned off" message when YouTube comments are disabled
Closes #1092 - Detect messageRenderer in YouTube API response when comments are disabled - Show a localized "Comments are turned off" message in HTML response - Add "commentsDisabled: true" flag to both JSON and HTML API responses - Add I18n locale string for the disabled message - Handle both empty continuationItems and messageRenderer presence
This commit is contained in:
parent
b7697e97c3
commit
feff91a225
@ -238,6 +238,7 @@
|
|||||||
"This channel does not exist.": "This channel does not exist.",
|
"This channel does not exist.": "This channel does not exist.",
|
||||||
"Could not get channel info.": "Could not get channel info.",
|
"Could not get channel info.": "Could not get channel info.",
|
||||||
"Could not fetch comments": "Could not fetch comments",
|
"Could not fetch comments": "Could not fetch comments",
|
||||||
|
"Comments are turned off": "Comments are turned off",
|
||||||
"comments_view_x_replies": "View {{count}} reply",
|
"comments_view_x_replies": "View {{count}} reply",
|
||||||
"comments_view_x_replies_plural": "View {{count}} replies",
|
"comments_view_x_replies_plural": "View {{count}} replies",
|
||||||
"`x` ago": "`x` ago",
|
"`x` ago": "`x` ago",
|
||||||
|
|||||||
@ -94,17 +94,45 @@ module Invidious::Comments
|
|||||||
|
|
||||||
if !contents
|
if !contents
|
||||||
if format == "json"
|
if format == "json"
|
||||||
return {"comments" => [] of String}.to_json
|
return {
|
||||||
|
"comments" => [] of String,
|
||||||
|
"commentCount" => 0,
|
||||||
|
"commentsDisabled" => true,
|
||||||
|
}.to_json
|
||||||
else
|
else
|
||||||
return {"contentHtml" => "", "commentCount" => 0}.to_json
|
return {
|
||||||
|
"contentHtml" => Frontend::Comments.template_youtube_disabled(locale),
|
||||||
|
"commentCount" => 0,
|
||||||
|
"commentsDisabled" => true,
|
||||||
|
}.to_json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
continuation_item_renderer = nil
|
continuation_item_renderer = nil
|
||||||
|
has_message_renderer = false
|
||||||
contents.as_a.reject! do |item|
|
contents.as_a.reject! do |item|
|
||||||
if item["continuationItemRenderer"]?
|
if item["continuationItemRenderer"]?
|
||||||
continuation_item_renderer = item["continuationItemRenderer"]
|
continuation_item_renderer = item["continuationItemRenderer"]
|
||||||
true
|
true
|
||||||
|
elsif item["messageRenderer"]?
|
||||||
|
has_message_renderer = true
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if has_message_renderer || contents.as_a.empty?
|
||||||
|
if format == "json"
|
||||||
|
return {
|
||||||
|
"comments" => [] of String,
|
||||||
|
"commentCount" => 0,
|
||||||
|
"commentsDisabled" => true,
|
||||||
|
}.to_json
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
"contentHtml" => Frontend::Comments.template_youtube_disabled(locale),
|
||||||
|
"commentCount" => 0,
|
||||||
|
"commentsDisabled" => true,
|
||||||
|
}.to_json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,14 @@
|
|||||||
module Invidious::Frontend::Comments
|
module Invidious::Frontend::Comments
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
|
def template_youtube_disabled(locale)
|
||||||
|
<<-END_HTML
|
||||||
|
<div class="h-box">
|
||||||
|
<p>#{I18n.translate(locale, "Comments are turned off")}</p>
|
||||||
|
</div>
|
||||||
|
END_HTML
|
||||||
|
end
|
||||||
|
|
||||||
def template_youtube(comments, locale, thin_mode, is_replies = false)
|
def template_youtube(comments, locale, thin_mode, is_replies = false)
|
||||||
String.build do |html|
|
String.build do |html|
|
||||||
root = comments["comments"].as_a
|
root = comments["comments"].as_a
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user