Skip to content

Commit

Permalink
Fix: すでに同じカスタム絵文字が存在する場合、スタンプを受け入れない問題
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Oct 7, 2023
1 parent c783d67 commit 46582b9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
14 changes: 8 additions & 6 deletions app/lib/activitypub/activity/like.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,17 @@ def process_emoji(tag)

return if custom_emoji_parser.shortcode.blank? || custom_emoji_parser.image_remote_url.blank?

emoji = CustomEmoji.find_by(shortcode: custom_emoji_parser.shortcode, domain: @account.domain)

return unless emoji.nil? || custom_emoji_parser.image_remote_url != emoji.image_remote_url || (custom_emoji_parser.updated_at && custom_emoji_parser.updated_at >= emoji.updated_at)

domain = emoji_tag['domain'] || URI.split(custom_emoji_parser.uri)[2] || @account.domain
domain = tag['domain'] || URI.split(custom_emoji_parser.uri)[2] || @account.domain
domain = nil if domain == Rails.configuration.x.local_domain || domain == Rails.configuration.x.web_domain

return if domain.present? && skip_download?(domain)

emoji = CustomEmoji.find_by(shortcode: custom_emoji_parser.shortcode, domain: domain)

return emoji unless emoji.nil? ||
custom_emoji_parser.image_remote_url != emoji.image_remote_url ||
(custom_emoji_parser.updated_at && custom_emoji_parser.updated_at >= emoji.updated_at) ||
custom_emoji_parser.license != emoji.license

begin
emoji ||= CustomEmoji.new(
domain: domain,
Expand Down
29 changes: 29 additions & 0 deletions spec/lib/activitypub/activity/like_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,35 @@
end
end

context 'with custom emoji but that is existing on local server' do
let(:content) { ':tinking:' }
let(:tag) do
{
id: 'https://example.com/aaa',
type: 'Emoji',
icon: {
url: 'http://example.com/emoji.png',
},
name: 'tinking',
license: 'Everyone but Ohagi',
}
end

before do
Fabricate(:custom_emoji, domain: 'example.com', uri: 'https://example.com/aaa', image_remote_url: 'http://example.com/emoji.png', shortcode: 'tinking', license: 'Everyone but Ohagi')
end

it 'create emoji reaction' do
expect(subject.count).to eq 1
expect(subject.first.name).to eq 'tinking'
expect(subject.first.account).to eq sender
expect(subject.first.custom_emoji).to_not be_nil
expect(subject.first.custom_emoji.shortcode).to eq 'tinking'
expect(subject.first.custom_emoji.domain).to eq 'example.com'
expect(sender.favourited?(status)).to be false
end
end

context 'with custom emoji and custom domain' do
let(:content) { ':tinking:' }
let(:tag) do
Expand Down

0 comments on commit 46582b9

Please sign in to comment.