mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
fix validation error (media only status) (#6684)
* fix validation error (media only status) * Incorporating review suggestions * Reflect similar fix to OStatus side * Fix not to include media in transaction * Restore the limit of the number of media * Fix not to return nil
This commit is contained in:
parent
4ca60c665e
commit
6dcf96271e
@ -20,13 +20,12 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
private
|
||||
|
||||
def process_status
|
||||
media_attachments = process_attachments
|
||||
status_params = process_status_params
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
@status = Status.create!(status_params)
|
||||
|
||||
process_tags(@status)
|
||||
attach_media(@status, media_attachments)
|
||||
end
|
||||
|
||||
resolve_thread(@status)
|
||||
@ -40,7 +39,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
status
|
||||
end
|
||||
|
||||
def status_params
|
||||
def process_status_params
|
||||
{
|
||||
uri: @object['id'],
|
||||
url: object_url || @object['id'],
|
||||
@ -54,6 +53,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
visibility: visibility_from_audience,
|
||||
thread: replied_to_status,
|
||||
conversation: conversation_from_uri(@object['conversation']),
|
||||
media_attachments: process_attachments.take(4),
|
||||
}
|
||||
end
|
||||
|
||||
@ -108,7 +108,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
end
|
||||
|
||||
def process_attachments
|
||||
return if @object['attachment'].nil?
|
||||
return [] if @object['attachment'].nil?
|
||||
|
||||
media_attachments = []
|
||||
|
||||
@ -132,13 +132,6 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
media_attachments
|
||||
end
|
||||
|
||||
def attach_media(status, media_attachments)
|
||||
return if media_attachments.blank?
|
||||
|
||||
media = MediaAttachment.where(status_id: nil, id: media_attachments.take(4).map(&:id))
|
||||
media.update(status_id: status.id)
|
||||
end
|
||||
|
||||
def resolve_thread(status)
|
||||
return unless status.reply? && status.thread.nil?
|
||||
ThreadResolveWorker.perform_async(status.id, in_reply_to_uri)
|
||||
|
@ -29,7 +29,7 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
|
||||
# Skip if the reblogged status is not public
|
||||
return if cached_reblog && !(cached_reblog.public_visibility? || cached_reblog.unlisted_visibility?)
|
||||
|
||||
media_attachments = save_media
|
||||
media_attachments = save_media.take(4)
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
status = Status.create!(
|
||||
@ -44,12 +44,12 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
|
||||
language: content_language,
|
||||
visibility: visibility_scope,
|
||||
conversation: find_or_create_conversation,
|
||||
thread: thread? ? find_status(thread.first) || find_activitypub_status(thread.first, thread.second) : nil
|
||||
thread: thread? ? find_status(thread.first) || find_activitypub_status(thread.first, thread.second) : nil,
|
||||
media_attachments: media_attachments
|
||||
)
|
||||
|
||||
save_mentions(status)
|
||||
save_hashtags(status)
|
||||
attach_media(status, media_attachments)
|
||||
save_emojis(status)
|
||||
end
|
||||
|
||||
@ -159,13 +159,6 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
|
||||
media_attachments
|
||||
end
|
||||
|
||||
def attach_media(parent, media_attachments)
|
||||
return if media_attachments.blank?
|
||||
|
||||
media = MediaAttachment.where(status_id: nil, id: media_attachments.take(4).map(&:id))
|
||||
media.update(status_id: parent.id)
|
||||
end
|
||||
|
||||
def save_emojis(parent)
|
||||
do_not_download = DomainBlock.find_by(domain: parent.account.domain)&.reject_media?
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user