about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-02-26 23:09:18 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-02-26 23:09:18 +0100
commit063432d7e352a0dfb7da0e198886b88e3b8a55bb (patch)
treee44452c86cfecb5d3f2d8082b3aa6a8e91335d01
parent1b8d3375c874c0ee5374000500075df026c56a16 (diff)
parent9433d03705d3aa86a059d82ffc549c699092912d (diff)
Merge branch 'fix_462' of https://github.com/rmhasan/mastodon into rmhasan-fix_462
-rw-r--r--app/controllers/api/v1/statuses_controller.rb11
-rw-r--r--app/services/post_status_service.rb18
2 files changed, 20 insertions, 9 deletions
diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb
index 69cbdce5d..2ffd4a018 100644
--- a/app/controllers/api/v1/statuses_controller.rb
+++ b/app/controllers/api/v1/statuses_controller.rb
@@ -62,12 +62,11 @@ class Api::V1::StatusesController < ApiController
   end
 
   def create
-    @status = PostStatusService.new.call(current_user.account, params[:status], params[:in_reply_to_id].blank? ? nil : Status.find(params[:in_reply_to_id]), media_ids: params[:media_ids],
-                                                                                                                                                             sensitive: params[:sensitive],
-                                                                                                                                                             spoiler_text: params[:spoiler_text],
-                                                                                                                                                             visibility: params[:visibility],
-                                                                                                                                                             application: doorkeeper_token.application)
-
+      @status = PostStatusService.new.call(current_user.account, params[:status], params[:in_reply_to_id].blank? ? nil : Status.find(params[:in_reply_to_id]), media_ids: params[:media_ids],
+                                                                                                                                                               sensitive: params[:sensitive],
+                                                                                                                                                               spoiler_text: params[:spoiler_text],
+                                                                                                                                                               visibility: params[:visibility],
+                                                                                                                                                               application: doorkeeper_token.application)
     render action: :show
   end
 
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index 979941c84..7ead80430 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,21 @@ 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)
-
     media = MediaAttachment.where(status_id: nil).where(id: media_ids.take(4).map(&:to_i))
+    if media.length > 1
+      media.each do |m|
+        if m.video?
+          raise Mastodon::NotPermitted, 'Cannot attach a video to a toot that already contains images'
+        end
+      end
+    end
+    return media
+  end
+
+  def attach_media(status, media)
+    return if media.nil?
     media.update(status_id: status.id)
   end