about summary refs log tree commit diff
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-12-12 04:32:38 -0600
committermultiple creatures <dev@multiple-creature.party>2019-12-12 04:32:38 -0600
commit49c7092f7ecd94e417226dad1c53f2e98544b328 (patch)
treedd9fc3051a5ecdfb6b9468426a4570c98f79bb31
parent2be54072b1ce4b2390641cd45b568465b5dcb5fc (diff)
make it possible to process & send out mentions in separate steps
-rw-r--r--app/services/process_mentions_service.rb34
1 files changed, 18 insertions, 16 deletions
diff --git a/app/services/process_mentions_service.rb b/app/services/process_mentions_service.rb
index 86c3be70c..85a22128c 100644
--- a/app/services/process_mentions_service.rb
+++ b/app/services/process_mentions_service.rb
@@ -7,34 +7,36 @@ class ProcessMentionsService < BaseService
   # local mention pointers, send Salmon notifications to mentioned
   # remote users
   # @param [Status] status
-  def call(status, skip_notify: false)
+  def call(status, skip_process: false, skip_notify: false)
     return unless status.local? && !status.draft?
 
     @status  = status
     mentions = Mention.where(status: status).to_a
 
-    status.text = status.text.gsub(Account::MENTION_RE) do |match|
-      username, domain  = Regexp.last_match(1).split('@')
-      mentioned_account = Account.find_remote(username, domain)
+    unless skip_process
+      status.text = status.text.gsub(Account::MENTION_RE) do |match|
+        username, domain  = Regexp.last_match(1).split('@')
+        mentioned_account = Account.find_remote(username, domain)
 
-      next match unless domain.nil? || '.'.in?(domain)
+        next match unless domain.nil? || '.'.in?(domain)
 
-      if mention_undeliverable?(mentioned_account)
-        begin
-          mentioned_account = resolve_account_service.call(Regexp.last_match(1))
-        rescue Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::UnexpectedResponseError
-          mentioned_account = nil
+        if mention_undeliverable?(mentioned_account)
+          begin
+            mentioned_account = resolve_account_service.call(Regexp.last_match(1))
+          rescue Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::UnexpectedResponseError
+            mentioned_account = nil
+          end
         end
-      end
 
-      next match if mention_undeliverable?(mentioned_account) || mentioned_account&.suspended?
+        next match if mention_undeliverable?(mentioned_account) || mentioned_account&.suspended?
 
-      mentions << mentioned_account.mentions.where(status: status).first_or_create(status: status)
+        mentions << mentioned_account.mentions.where(status: status).first_or_create(status: status)
 
-      "@#{mentioned_account.acct}"
-    end
+        "@#{mentioned_account.acct}"
+      end
 
-    status.save!
+      status.save!
+    end
 
     return if skip_notify
     mentions.uniq.each { |mention| create_notification(mention) }