Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twidere mention workaround #5552

Merged
merged 2 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/javascript/mastodon/features/compose/util/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
2 changes: 1 addition & 1 deletion app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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
Expand Down
9 changes: 6 additions & 3 deletions app/services/process_mentions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down