about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-07-20 03:58:14 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:44:01 -0500
commit3366a957219b15f5ab6f6eabbf5466e1e12082de (patch)
tree83397d725b7b93070137854e849a0afcc421f553 /app/services
parent21438b54bdaf3c557ec9ebbc482a2c418d8c64f8 (diff)
[Feature] Add command tags; add #!edit and #!publish commands for mobile users
Diffstat (limited to 'app/services')
-rw-r--r--app/services/post_status_service.rb7
-rw-r--r--app/services/process_command_tags_service.rb10
-rw-r--r--app/services/publish_status_service.rb22
-rw-r--r--app/services/update_status_service.rb4
4 files changed, 41 insertions, 2 deletions
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index 5ddc1aeeb..132e91907 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -88,6 +88,7 @@ class PostStatusService < BaseService
       @status = @account.statuses.create!(status_attributes)
     end
 
+    process_command_tags_service.call(@account, @status)
     process_hashtags_service.call(@status, nil, @tag_names)
     process_mentions_service.call(@status, mentions: @mentions, deliver: @options[:publish])
   end
@@ -148,6 +149,10 @@ class PostStatusService < BaseService
     ProcessHashtagsService.new
   end
 
+  def process_command_tags_service
+    ProcessCommandTagsService.new
+  end
+
   def scheduled?
     @scheduled_at.present?
   end
@@ -178,8 +183,10 @@ class PostStatusService < BaseService
 
   def bump_potential_friendship!
     return if !@status.reply? || @account.id == @status.in_reply_to_account_id
+
     ActivityTracker.increment('activity:interactions')
     return if @account.following?(@status.in_reply_to_account_id)
+
     PotentialFriendshipTracker.record(@account.id, @status.in_reply_to_account_id, :reply)
   end
 
diff --git a/app/services/process_command_tags_service.rb b/app/services/process_command_tags_service.rb
new file mode 100644
index 000000000..2d8180673
--- /dev/null
+++ b/app/services/process_command_tags_service.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class ProcessCommandTagsService < BaseService
+  def call(account, status, raise_if_no_output: true)
+    CommandTag::Processor.new(account, status).process!
+    raise Mastodon::LengthValidationError, 'Processed command tags yielded no output.' if raise_if_no_output && status.destroyed?
+
+    status
+  end
+end
diff --git a/app/services/publish_status_service.rb b/app/services/publish_status_service.rb
new file mode 100644
index 000000000..737186a17
--- /dev/null
+++ b/app/services/publish_status_service.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+class PublishStatusService < BaseService
+  def call(status)
+    return if status.published?
+
+    status.update!(published: true)
+
+    ProcessMentionsService.new.call(status)
+
+    LinkCrawlWorker.perform_in(rand(1..30).seconds, status.id) unless status.spoiler_text?
+    DistributionWorker.perform_async(status.id)
+    ActivityPub::DistributionWorker.perform_async(status.id) if status.local? && !status.local_only?
+
+    return if !status.reply? || status.account.id == status.in_reply_to_account_id
+
+    ActivityTracker.increment('activity:interactions')
+
+    return if status.account.following?(status.in_reply_to_account_id)
+
+    PotentialFriendshipTracker.record(status.account.id, status.in_reply_to_account_id, :reply)
+  end
+end
diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb
index 440b99ce7..795e43d01 100644
--- a/app/services/update_status_service.rb
+++ b/app/services/update_status_service.rb
@@ -13,7 +13,6 @@ class UpdateStatusService < BaseService
     media_attachments
     media_attachment_ids
     application
-    rate_limit
   ).freeze
 
   # Updates the content of an existing status.
@@ -21,7 +20,7 @@ class UpdateStatusService < BaseService
   # @param [Hash] params The attributes of the new status.
   # @param [Enumerable] mentions Additional mentions added to the status.
   # @param [Enumerable] tags New tags for the status to belong to (implicit tags are preserved).
-  def call(status, params, mentions, tags)
+  def call(status, params, mentions = nil, tags = nil)
     raise ActiveRecord::RecordNotFound if status.blank? || status.discarded? || status.destroyed?
     return status if params.blank?
 
@@ -47,6 +46,7 @@ class UpdateStatusService < BaseService
 
     ApplicationRecord.transaction do
       @status.update!(@params)
+      ProcessCommandTagsService.new.call(@account, @status) if @account.local?
       detach_deleted_tags
       attach_updated_tags
     end