From ac7e36cdd391081f6c2d303c965ec6c9d21163f8 Mon Sep 17 00:00:00 2001 From: Essem Date: Thu, 5 Oct 2023 17:05:15 -0500 Subject: [PATCH] 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. --- app/helpers/statuses_helper.rb | 8 +++++++- app/serializers/oembed_serializer.rb | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/helpers/statuses_helper.rb b/app/helpers/statuses_helper.rb index 286c53d834..74ebe3dabc 100644 --- a/app/helpers/statuses_helper.rb +++ b/app/helpers/statuses_helper.rb @@ -18,7 +18,7 @@ module StatusesHelper end end - def media_summary(status) + def attachment_types(status) attachments = { image: 0, video: 0, audio: 0 } status.ordered_media_attachments.each do |media| @@ -31,6 +31,12 @@ module StatusesHelper 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(' ยท ') return if text.blank? diff --git a/app/serializers/oembed_serializer.rb b/app/serializers/oembed_serializer.rb index d6261d7242..0ccb7cba5a 100644 --- a/app/serializers/oembed_serializer.rb +++ b/app/serializers/oembed_serializer.rb @@ -2,6 +2,7 @@ class OEmbedSerializer < ActiveModel::Serializer include RoutingHelper + include StatusesHelper include ActionView::Helpers::TagHelper attributes :type, :version, :author_name, @@ -17,7 +18,7 @@ class OEmbedSerializer < ActiveModel::Serializer end 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 def author_url