mirror of https://github.com/iv-org/invidious.git
Fix YT link for post comments
This commit is contained in:
parent
71da6c2fec
commit
0c414adbeb
|
@ -57,7 +57,7 @@ module Invidious::Comments
|
||||||
return initial_data
|
return initial_data
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_youtube(id, response, format, locale, thin_mode, type="video", sort_by = "top")
|
def parse_youtube(id, response, format, locale, thin_mode, sort_by = "top", type = "video", ucid = nil)
|
||||||
contents = nil
|
contents = nil
|
||||||
|
|
||||||
if on_response_received_endpoints = response["onResponseReceivedEndpoints"]?
|
if on_response_received_endpoints = response["onResponseReceivedEndpoints"]?
|
||||||
|
@ -115,6 +115,10 @@ module Invidious::Comments
|
||||||
json.field "commentCount", comment_count
|
json.field "commentCount", comment_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !ucid.nil?
|
||||||
|
json.field "authorId", ucid
|
||||||
|
end
|
||||||
|
|
||||||
if type == "post"
|
if type == "post"
|
||||||
json.field "postId", id
|
json.field "postId", id
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module Invidious::Frontend::Comments
|
module Invidious::Frontend::Comments
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
def template_youtube(comments, locale, thin_mode, id, type="video", is_replies = false)
|
def template_youtube(comments, locale, thin_mode, id, type = "video", is_replies = false)
|
||||||
String.build do |html|
|
String.build do |html|
|
||||||
root = comments["comments"].as_a
|
root = comments["comments"].as_a
|
||||||
root.each do |child|
|
root.each do |child|
|
||||||
|
@ -27,7 +27,7 @@ module Invidious::Frontend::Comments
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
END_HTML
|
END_HTML
|
||||||
elsif comments["authorId"]? && !comments["singlePost"]?
|
elsif comments["authorId"]? && !comments["singlePost"]? && type != "post"
|
||||||
# for posts we should display a link to the post
|
# for posts we should display a link to the post
|
||||||
replies_count_text = translate_count(locale,
|
replies_count_text = translate_count(locale,
|
||||||
"comments_view_x_replies",
|
"comments_view_x_replies",
|
||||||
|
@ -151,7 +151,12 @@ module Invidious::Frontend::Comments
|
||||||
|
|
|
|
||||||
END_HTML
|
END_HTML
|
||||||
|
|
||||||
if comments["videoId"]?
|
if type == "post" && !comments["singlePost"]?
|
||||||
|
html << <<-END_HTML
|
||||||
|
<a href="https://www.youtube.com/channel/#{comments["authorId"]}/community?lb=#{id}&lc=#{child["commentId"]}" title="#{translate(locale, "YouTube comment permalink")}">[YT]</a>
|
||||||
|
|
|
||||||
|
END_HTML
|
||||||
|
elsif comments["videoId"]?
|
||||||
html << <<-END_HTML
|
html << <<-END_HTML
|
||||||
<a rel="noreferrer noopener" href="https://www.youtube.com/watch?v=#{comments["videoId"]}&lc=#{child["commentId"]}" title="#{translate(locale, "YouTube comment permalink")}">[YT]</a>
|
<a rel="noreferrer noopener" href="https://www.youtube.com/watch?v=#{comments["videoId"]}&lc=#{child["commentId"]}" title="#{translate(locale, "YouTube comment permalink")}">[YT]</a>
|
||||||
|
|
|
|
||||||
|
|
|
@ -441,8 +441,7 @@ module Invidious::Routes::API::V1::Channels
|
||||||
else
|
else
|
||||||
comments = YoutubeAPI.browse(continuation: continuation)
|
comments = YoutubeAPI.browse(continuation: continuation)
|
||||||
end
|
end
|
||||||
|
return Comments.parse_youtube(id, comments, format, locale, thin_mode, type: "post", ucid: ucid)
|
||||||
return Comments.parse_youtube(id, comments, format, locale, thin_mode, "post")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.channels(env)
|
def self.channels(env)
|
||||||
|
|
|
@ -270,8 +270,7 @@ module Invidious::Routes::Channels
|
||||||
|
|
||||||
if nojs
|
if nojs
|
||||||
comments = Comments.fetch_community_post_comments(ucid, id)
|
comments = Comments.fetch_community_post_comments(ucid, id)
|
||||||
|
comment_html = JSON.parse(Comments.parse_youtube(id, comments, "html", locale, thin_mode, type: "post", ucid: ucid))["contentHtml"]
|
||||||
comment_html = JSON.parse(Comments.parse_youtube(id, comments, "html", locale, thin_mode, "post"))["contentHtml"]
|
|
||||||
end
|
end
|
||||||
templated "post"
|
templated "post"
|
||||||
end
|
end
|
||||||
|
|
|
@ -366,7 +366,7 @@ module Invidious::Routes::Watch
|
||||||
else
|
else
|
||||||
comments = YoutubeAPI.browse(continuation: continuation)
|
comments = YoutubeAPI.browse(continuation: continuation)
|
||||||
end
|
end
|
||||||
comment_html = JSON.parse(Comments.parse_youtube(id, comments, "html", locale, thin_mode, "post"))["contentHtml"]
|
comment_html = JSON.parse(Comments.parse_youtube(id, comments, "html", locale, thin_mode, type: "post", ucid: ucid))["contentHtml"]
|
||||||
else
|
else
|
||||||
# video comments
|
# video comments
|
||||||
if source == "youtube"
|
if source == "youtube"
|
||||||
|
|
Loading…
Reference in New Issue