diff options
author | Fire Demon <firedemon@creature.cafe> | 2020-06-30 17:33:55 -0500 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-08-30 05:41:03 -0500 |
commit | eaf9bc1a428b338ee666f1da1e32eed7e3b6b25e (patch) | |
tree | aeec5fdde79d6e4fa354da326a540811b5576907 /app/services/process_mentions_service.rb | |
parent | 5d5d88e4f65df4c190afeb407167c153584be108 (diff) |
[Feature] Add in-place post editing
Diffstat (limited to 'app/services/process_mentions_service.rb')
-rw-r--r-- | app/services/process_mentions_service.rb | 47 |
1 files changed, 6 insertions, 41 deletions
diff --git a/app/services/process_mentions_service.rb b/app/services/process_mentions_service.rb index f45422970..f3ce81ef1 100644 --- a/app/services/process_mentions_service.rb +++ b/app/services/process_mentions_service.rb @@ -7,42 +7,15 @@ class ProcessMentionsService < BaseService # local mention pointers, send Salmon notifications to mentioned # remote users # @param [Status] status - def call(status) + # @option [Enumerable] :mentions Mentions to include + # @option [Boolean] :reveal_implicit_mentions Append implicit mentions to text + def call(status, mentions: [], reveal_implicit_mentions: true) return unless status.local? - @status = status - mentions = [] + @status = status + @status.text, mentions = ResolveMentionsService.new.call(@status, mentions: mentions, reveal_implicit_mentions: reveal_implicit_mentions) + @status.save! - status.text = status.text.gsub(Account::MENTION_RE) do |match| - username, domain = Regexp.last_match(1).split('@') - - domain = begin - if TagManager.instance.local_domain?(domain) - nil - else - TagManager.instance.normalize_domain(domain) - end - end - - mentioned_account = Account.find_remote(username, 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 - end - end - - next match if mention_undeliverable?(mentioned_account) || mentioned_account&.suspended? - - mention = mentioned_account.mentions.new(status: status) - mentions << mention if mention.save - - "@#{mentioned_account.acct}" - end - - status.save! check_for_spam(status) mentions.each { |mention| create_notification(mention) } @@ -50,10 +23,6 @@ class ProcessMentionsService < BaseService private - def mention_undeliverable?(mentioned_account) - mentioned_account.nil? || (!mentioned_account.local? && mentioned_account.ostatus?) - end - def create_notification(mention) mentioned_account = mention.account @@ -69,10 +38,6 @@ class ProcessMentionsService < BaseService @activitypub_json = Oj.dump(serialize_payload(ActivityPub::ActivityPresenter.from_status(@status), ActivityPub::ActivitySerializer, signer: @status.account)) end - def resolve_account_service - ResolveAccountService.new - end - def check_for_spam(status) SpamCheck.perform(status) end |