Skip to content

Commit

Permalink
fix lint, improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkyProgrammer committed Apr 9, 2024
1 parent 5ee40f8 commit b77b874
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/invidious/comments/youtube.cr
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ module Invidious::Comments
end
end

mutations = response.dig?("frameworkUpdates", "entityBatchUpdate", "mutations").try &.as_a || [] of JSON::Any

response = JSON.build do |json|

Check failure on line 109 in src/invidious/comments/youtube.cr

View workflow job for this annotation

GitHub Actions / build - crystal: 1.9.2, stable: true

instantiating 'JSON.build()'

Check failure on line 109 in src/invidious/comments/youtube.cr

View workflow job for this annotation

GitHub Actions / build - crystal: 1.10.1, stable: true

instantiating 'JSON.build()'

Check failure on line 109 in src/invidious/comments/youtube.cr

View workflow job for this annotation

GitHub Actions / build - crystal: 1.8.2, stable: true

instantiating 'JSON:Module#build()'

Check failure on line 109 in src/invidious/comments/youtube.cr

View workflow job for this annotation

GitHub Actions / build - crystal: 1.7.3, stable: true

instantiating 'JSON:Module#build()'
json.object do
if header
Expand Down Expand Up @@ -135,9 +137,9 @@ module Invidious::Comments
cvm = node.dig("commentViewModel", "commentViewModel")
comment_key = cvm["commentKey"]
toolbar_key = cvm["toolbarStateKey"]
if mutations = response.dig?("frameworkUpdates", "entityBatchUpdate", "mutations")
comment_mutation = mutations.as_a.find { |i| i.dig?("payload", "commentEntityPayload", "key") == comment_key}
toolbar_mutation = mutations.as_a.find { |i| i.dig?("entityKey") == toolbar_key}
if mutations.size != 0
comment_mutation = mutations.as_a.find { |i| i.dig?("payload", "commentEntityPayload", "key") == comment_key }
toolbar_mutation = mutations.as_a.find { |i| i.dig?("entityKey") == toolbar_key }
if !comment_mutation.nil? && !toolbar_mutation.nil?
html_content = comment_mutation.dig("payload", "commentEntityPayload", "properties", "content", "content").as_s
if comment_author = comment_mutation.dig?("payload", "commentEntityPayload", "author")
Expand All @@ -156,8 +158,8 @@ module Invidious::Comments
end
end
end
json.field "authorIsChannelOwner", comment_author["isCreator"].as_bool
json.field "isSponsor", (comment_author["sponsorBadgeUrl"]?!= nil)
json.field "authorIsChannelOwner", comment_author["isCreator"].as_bool
json.field "isSponsor", (comment_author["sponsorBadgeUrl"]? != nil)
if comment_author["sponsorBadgeUrl"]?
# Sponsor icon thumbnails always have one object and there's only ever the url property in it
json.field "sponsorIconUrl", comment_author["sponsorBadgeUrl"].to_s
Expand Down

0 comments on commit b77b874

Please sign in to comment.