From 1d9c77063e9e0450e3f0f0e0045d57271d4bdfcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KMY=EF=BC=88=E9=9B=AA=E3=81=82=E3=81=99=E3=81=8B=EF=BC=89?= Date: Wed, 18 Oct 2023 10:56:21 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=BB=96=E3=81=AE=E3=82=B5=E3=83=BC?= =?UTF-8?q?=E3=83=90=E3=83=BC=E3=81=AE=E5=90=8C=E3=81=98=E7=B5=B5=E6=96=87?= =?UTF-8?q?=E5=AD=97=E3=82=92=E8=A4=87=E6=95=B0=E3=81=A4=E3=81=91=E3=82=89?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E5=95=8F=E9=A1=8C=20(#141)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * スタンプ機能のリファクタリング、投稿の反応者へも配送 * Fix: 他のサーバーの絵文字を複数つけられる問題 --- app/services/emoji_react_service.rb | 6 ++-- spec/services/emoji_react_service_spec.rb | 40 ++++++++++++++++++----- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/app/services/emoji_react_service.rb b/app/services/emoji_react_service.rb index 5e30e005d6cafa..f8bc622d1f782f 100644 --- a/app/services/emoji_react_service.rb +++ b/app/services/emoji_react_service.rb @@ -17,14 +17,14 @@ def call(account, status, name) @status = status with_redis_lock("emoji_reaction:#{status.id}") do - @emoji_reaction = EmojiReaction.find_by(account: account, status: status, name: name) - raise Mastodon::ValidationError, I18n.t('reactions.errors.duplication') unless @emoji_reaction.nil? - shortcode, domain = name.split('@') domain = nil if TagManager.instance.local_domain?(domain) custom_emoji = CustomEmoji.find_by(shortcode: shortcode, domain: domain) return if domain.present? && !EmojiReaction.exists?(status: status, custom_emoji: custom_emoji) + @emoji_reaction = EmojiReaction.find_by(account: account, status: status, name: shortcode, custom_emoji: custom_emoji) + raise Mastodon::ValidationError, I18n.t('reactions.errors.duplication') unless @emoji_reaction.nil? + @emoji_reaction = EmojiReaction.create!(account: account, status: status, name: shortcode, custom_emoji: custom_emoji) status.touch # rubocop:disable Rails/SkipsModelValidations diff --git a/spec/services/emoji_react_service_spec.rb b/spec/services/emoji_react_service_spec.rb index bf03eb5bf8cda3..8ba0466ef111e5 100644 --- a/spec/services/emoji_react_service_spec.rb +++ b/spec/services/emoji_react_service_spec.rb @@ -19,15 +19,6 @@ expect(subject.first.custom_emoji_id).to be_nil end - context 'with name duplication on same account' do - before { Fabricate(:emoji_reaction, status: status, name: '😀') } - - it 'react with emoji' do - expect(subject.count).to eq 1 - expect(subject.first.name).to eq '😀' - end - end - context 'when multiple reactions by same account' do let(:name) { '😂' } @@ -139,6 +130,37 @@ end end + context 'with name duplication of unicode emoji on same account' do + before { Fabricate(:emoji_reaction, status: status, name: '😀') } + + it 'react with emoji' do + expect(subject.count).to eq 1 + expect(subject.first.name).to eq '😀' + end + end + + context 'with name duplication of local cuetom emoji on same account' do + let(:name) { 'ohagi' } + let!(:custom_emoji) { Fabricate(:custom_emoji, shortcode: 'ohagi') } + + before { Fabricate(:emoji_reaction, account: sender, status: status, name: 'ohagi', custom_emoji: custom_emoji) } + + it 'react with emoji' do + expect { subject.count }.to raise_error Mastodon::ValidationError + end + end + + context 'with name duplication of remote cuetom emoji on same account' do + let(:name) { 'ohagi@foo.bar' } + let!(:custom_emoji) { Fabricate(:custom_emoji, shortcode: 'ohagi', domain: 'foo.bar', uri: 'https://foo.bar/emoji/ohagi') } + + before { Fabricate(:emoji_reaction, account: sender, status: status, name: 'ohagi', custom_emoji: custom_emoji) } + + it 'react with emoji' do + expect { subject.count }.to raise_error Mastodon::ValidationError + end + end + context 'when has remote followers' do let!(:bob) { Fabricate(:account, domain: 'foo.bar', uri: 'https://foo.bar/actor', inbox_url: 'https://foo.bar/inbox', protocol: 'activitypub') }