Fix YT link for post comments

pull/4176/head
ChunkyProgrammer 2023-10-16 12:46:23 -04:00
rodzic d290629e74
commit 01f5f2e9c5
5 zmienionych plików z 16 dodań i 9 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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 href="https://www.youtube.com/watch?v=#{comments["videoId"]}&lc=#{child["commentId"]}" title="#{translate(locale, "YouTube comment permalink")}">[YT]</a> <a href="https://www.youtube.com/watch?v=#{comments["videoId"]}&lc=#{child["commentId"]}" title="#{translate(locale, "YouTube comment permalink")}">[YT]</a>
| |

Wyświetl plik

@ -394,8 +394,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)

Wyświetl plik

@ -231,8 +231,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

Wyświetl plik

@ -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"