about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/javascript/mastodon/features/compose/util/counter.js2
-rw-r--r--app/models/account.rb2
-rw-r--r--app/services/process_mentions_service.rb9
3 files changed, 8 insertions, 5 deletions
diff --git a/app/javascript/mastodon/features/compose/util/counter.js b/app/javascript/mastodon/features/compose/util/counter.js
index e6d2487c5..700ba2163 100644
--- a/app/javascript/mastodon/features/compose/util/counter.js
+++ b/app/javascript/mastodon/features/compose/util/counter.js
@@ -5,5 +5,5 @@ const urlPlaceholder = 'xxxxxxxxxxxxxxxxxxxxxxx';
 export function countableText(inputText) {
   return inputText
     .replace(urlRegex, urlPlaceholder)
-    .replace(/(?:^|[^\/\w])@(([a-z0-9_]+)@[a-z0-9\.\-]+[a-z0-9]+)/ig, '@$2');
+    .replace(/(^|[^\/\w])@(([a-z0-9_]+)@[a-z0-9\.\-]+[a-z0-9]+)/ig, '$1@$3');
 };
diff --git a/app/models/account.rb b/app/models/account.rb
index 1142e7c79..7e4d29f96 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -45,7 +45,7 @@
 #
 
 class Account < ApplicationRecord
-  MENTION_RE = /(?:^|[^\/[:word:]])@(([a-z0-9_]+)(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i
+  MENTION_RE = /(?<=^|[^\/[:word:]])@(([a-z0-9_]+)(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i
 
   include AccountAvatar
   include AccountFinderConcern
diff --git a/app/services/process_mentions_service.rb b/app/services/process_mentions_service.rb
index aa649652c..65e6b1361 100644
--- a/app/services/process_mentions_service.rb
+++ b/app/services/process_mentions_service.rb
@@ -10,18 +10,21 @@ class ProcessMentionsService < BaseService
   def call(status)
     return unless status.local?
 
-    status.text.scan(Account::MENTION_RE).each do |match|
+    status.text = status.text.gsub(Account::MENTION_RE) do |match|
       begin
-        mentioned_account = resolve_remote_account_service.call(match.first.to_s)
+        mentioned_account = resolve_remote_account_service.call($1)
       rescue Goldfinger::Error, HTTP::Error
         mentioned_account = nil
       end
 
-      next if mentioned_account.nil? || (mentioned_account.ostatus? && status.stream_entry.hidden?)
+      next match if mentioned_account.nil? || (mentioned_account.ostatus? && status.stream_entry.hidden?)
 
       mentioned_account.mentions.where(status: status).first_or_create(status: status)
+      "@#{mentioned_account.acct}"
     end
 
+    status.save!
+
     status.mentions.includes(:account).each do |mention|
       create_notification(status, mention)
     end