about summary refs log tree commit diff
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-07-18 12:06:45 -0500
committermultiple creatures <dev@multiple-creature.party>2019-07-18 12:06:45 -0500
commit7f195145277d8e4e10ae086a99a30a83ec41b58d (patch)
tree8990c766df8a6cb872b366f8e3e29cb9b839a3ae
parentb28fae301a338abe085780f6e74560190bd1c3e7 (diff)
better handling of bangtag-only posts that produce no output
-rw-r--r--app/controllers/api/v1/statuses_controller.rb6
-rw-r--r--app/lib/bangtags.rb12
-rw-r--r--app/services/post_status_service.rb5
3 files changed, 17 insertions, 6 deletions
diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb
index 52d0fb9bc..a9728f997 100644
--- a/app/controllers/api/v1/statuses_controller.rb
+++ b/app/controllers/api/v1/statuses_controller.rb
@@ -58,7 +58,11 @@ class Api::V1::StatusesController < Api::BaseController
                                          content_type: status_params[:content_type],
                                          idempotency: request.headers['Idempotency-Key'])
 
-    render json: @status, serializer: @status.is_a?(ScheduledStatus) ? REST::ScheduledStatusSerializer : REST::StatusSerializer
+    if @status.nil?
+      raise Mastodon::ValidationError, 'Bangtags processed. No output.'
+    else
+      render json: @status, serializer: @status.is_a?(ScheduledStatus) ? REST::ScheduledStatusSerializer : REST::StatusSerializer
+    end
   end
 
   def destroy
diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb
index 40714097b..536606065 100644
--- a/app/lib/bangtags.rb
+++ b/app/lib/bangtags.rb
@@ -730,10 +730,14 @@ class Bangtags
 
     account.user.save
 
-    status.text = @chunks.join
-    status.save
-
-    postprocess_after_save
+    text = @chunks.join
+    if text.blank?
+      RemoveStatusService.new.call(@status)
+    else
+      status.text = text
+      status.save
+      postprocess_after_save
+    end
   end
 
   private
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index 6f4be1cfe..ea7a2c2c3 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -52,7 +52,7 @@ class PostStatusService < BaseService
     if scheduled?
       schedule_status!
     else
-      process_status!
+      return unless process_status!
       postprocess_status!
       bump_potential_friendship!
     end
@@ -148,8 +148,11 @@ class PostStatusService < BaseService
       @status = @account.statuses.create!(status_attributes)
     end
 
+    return false if @status.destroyed?
+
     process_hashtags_service.call(@status, @tags, @preloaded_tags)
     process_mentions_service.call(@status)
+    return true
   end
 
   def schedule_status!