Set oEmbed author to content when video is present

Discord won't show post content when a video is attached.
This essentially copies what FixTweet does to work around that.
This commit is contained in:
Essem 2023-10-05 17:05:15 -05:00
parent c85a1b83b3
commit ac7e36cdd3
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
2 changed files with 9 additions and 2 deletions

View file

@ -18,7 +18,7 @@ module StatusesHelper
end end
end end
def media_summary(status) def attachment_types(status)
attachments = { image: 0, video: 0, audio: 0 } attachments = { image: 0, video: 0, audio: 0 }
status.ordered_media_attachments.each do |media| status.ordered_media_attachments.each do |media|
@ -31,6 +31,12 @@ module StatusesHelper
end end
end end
attachments
end
def media_summary(status)
attachments = attachment_types(status)
text = attachments.to_a.reject { |_, value| value.zero? }.map { |key, value| I18n.t("statuses.attached.#{key}", count: value) }.join(' · ') text = attachments.to_a.reject { |_, value| value.zero? }.map { |key, value| I18n.t("statuses.attached.#{key}", count: value) }.join(' · ')
return if text.blank? return if text.blank?

View file

@ -2,6 +2,7 @@
class OEmbedSerializer < ActiveModel::Serializer class OEmbedSerializer < ActiveModel::Serializer
include RoutingHelper include RoutingHelper
include StatusesHelper
include ActionView::Helpers::TagHelper include ActionView::Helpers::TagHelper
attributes :type, :version, :author_name, attributes :type, :version, :author_name,
@ -17,7 +18,7 @@ class OEmbedSerializer < ActiveModel::Serializer
end end
def author_name def author_name
object.account.display_name.presence || object.account.username (attachment_types(object)[:video]).positive? ? status_description(object) : (object.account.display_name.presence || object.account.username)
end end
def author_url def author_url