diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-02-26 23:23:47 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-02-26 23:23:47 +0100 |
commit | a0df694c2431b30f2f1051cd9ddc9344229d600d (patch) | |
tree | 5ed179289819d61df1a4c15851389aa7d9b42f19 /app/services/post_status_service.rb | |
parent | 1b8d3375c874c0ee5374000500075df026c56a16 (diff) | |
parent | 5f511324b65f94d800dbbd3850214955d7d9eb73 (diff) |
Merge branch 'rmhasan-fix_462'
Diffstat (limited to 'app/services/post_status_service.rb')
-rw-r--r-- | app/services/post_status_service.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 979941c84..b8179f7dc 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -13,6 +13,7 @@ class PostStatusService < BaseService # @option [Doorkeeper::Application] :application # @return [Status] def call(account, text, in_reply_to = nil, options = {}) + media = validate_media!(options[:media_ids]) status = account.statuses.create!(text: text, thread: in_reply_to, sensitive: options[:sensitive], @@ -20,7 +21,7 @@ class PostStatusService < BaseService visibility: options[:visibility], application: options[:application]) - attach_media(status, options[:media_ids]) + attach_media(status, media) process_mentions_service.call(status) process_hashtags_service.call(status) @@ -33,10 +34,20 @@ class PostStatusService < BaseService private - def attach_media(status, media_ids) + def validate_media!(media_ids) return if media_ids.nil? || !media_ids.is_a?(Enumerable) + raise Mastodon::ValidationError, 'Cannot attach more than 4 files' if media_ids.size > 4 + media = MediaAttachment.where(status_id: nil).where(id: media_ids.take(4).map(&:to_i)) + + raise Mastodon::ValidationError, 'Cannot attach a video to a toot that already contains images' if media.size > 1 && media.find(&:video?) + + media + end + + def attach_media(status, media) + return if media.nil? media.update(status_id: status.id) end |