From c1093dd259c9e89fd71d9462d577a837a8870022 Mon Sep 17 00:00:00 2001 From: noellabo Date: Mon, 4 Jan 2021 05:10:18 +0900 Subject: [PATCH] Fix custom emoji compatibility in Misskey's display name --- .../styles/mastodon/components.scss | 2 +- .../activitypub/process_account_service.rb | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/javascript/styles/mastodon/components.scss b/app/javascript/styles/mastodon/components.scss index a634c29d3..0e0b8a202 100644 --- a/app/javascript/styles/mastodon/components.scss +++ b/app/javascript/styles/mastodon/components.scss @@ -769,7 +769,7 @@ font-size: inherit; vertical-align: middle; object-fit: contain; - margin: -.2ex .15em .2ex; + margin: -.2ex 0 .2ex; width: 16px; height: 16px; diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index 4ab6912e5..6be2b4782 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -14,6 +14,7 @@ class ActivityPub::ProcessAccountService < BaseService @uri = @json['id'] @username = username @domain = domain + @shortcodes = [] @collections = {} RedisLock.acquire(lock_options) do |lock| @@ -25,8 +26,8 @@ class ActivityPub::ProcessAccountService < BaseService @suspension_changed = false create_account if @account.nil? - update_account process_tags + update_account process_attachments process_duplicate_accounts! if @options[:verified_webfinger] @@ -93,7 +94,7 @@ class ActivityPub::ProcessAccountService < BaseService def set_immediate_attributes! @account.featured_collection_url = @json['featured'] || '' @account.devices_url = @json['devices'] || '' - @account.display_name = @json['name'] || '' + @account.display_name = fix_emoji(@json['name']) || '' @account.note = @json['summary'] || '' @account.locked = @json['manuallyApprovesFollowers'] || false @account.fields = property_values || {} @@ -328,6 +329,8 @@ class ActivityPub::ProcessAccountService < BaseService updated = tag['updated'] emoji = CustomEmoji.find_by(shortcode: shortcode, domain: @account.domain) + @shortcodes << shortcode unless emoji.nil? + return unless emoji.nil? || image_url != emoji.image_remote_url || (updated && updated >= emoji.updated_at) emoji ||= CustomEmoji.new(domain: @account.domain, shortcode: shortcode, uri: uri) @@ -342,4 +345,17 @@ class ActivityPub::ProcessAccountService < BaseService @account.identity_proofs.where(provider: provider, provider_username: provider_username).find_or_create_by(provider: provider, provider_username: provider_username, token: token) end + + def fix_emoji(text) + return text if text.blank? || @shortcodes.empty? + + fixed_text = text.dup + + @shortcodes.each do |shortcode| + fixed_text.gsub!(/([^\s\u200B])(:#{shortcode}:)/, "\\1\u200B\\2") + fixed_text.gsub!(/(:#{shortcode}:)([^\s\u200B])/, "\\1\u200B\\2") + end + + fixed_text + end end