about summary refs log tree commit diff
path: root/app/lib/ostatus/activity
diff options
context:
space:
mode:
authorMitarashiDango <MitarashiDango@users.noreply.github.com>2018-03-08 09:22:47 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-03-08 01:22:47 +0100
commit6dcf96271ee5b81ecb910f80f8218bb2a9b1b404 (patch)
treee083556bec65022bf903e86a7c0e55b6ebb47512 /app/lib/ostatus/activity
parent4ca60c665e02103b8730748c9b82b52bcd0d8d1c (diff)
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
Diffstat (limited to 'app/lib/ostatus/activity')
-rw-r--r--app/lib/ostatus/activity/creation.rb13
1 files changed, 3 insertions, 10 deletions
diff --git a/app/lib/ostatus/activity/creation.rb b/app/lib/ostatus/activity/creation.rb
index 7cf2d90dc..aa46267dc 100644
--- a/app/lib/ostatus/activity/creation.rb
+++ b/app/lib/ostatus/activity/creation.rb
@@ -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?