Fix: 他のサーバーの同じ絵文字を複数つけられる問題 (#141)
* スタンプ機能のリファクタリング、投稿の反応者へも配送 * Fix: 他のサーバーの絵文字を複数つけられる問題
This commit is contained in:
parent
b73eb1b847
commit
1d9c77063e
2 changed files with 34 additions and 12 deletions
|
@ -17,14 +17,14 @@ class EmojiReactService < BaseService
|
||||||
@status = status
|
@status = status
|
||||||
|
|
||||||
with_redis_lock("emoji_reaction:#{status.id}") do
|
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('@')
|
shortcode, domain = name.split('@')
|
||||||
domain = nil if TagManager.instance.local_domain?(domain)
|
domain = nil if TagManager.instance.local_domain?(domain)
|
||||||
custom_emoji = CustomEmoji.find_by(shortcode: shortcode, domain: domain)
|
custom_emoji = CustomEmoji.find_by(shortcode: shortcode, domain: domain)
|
||||||
return if domain.present? && !EmojiReaction.exists?(status: status, custom_emoji: custom_emoji)
|
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)
|
@emoji_reaction = EmojiReaction.create!(account: account, status: status, name: shortcode, custom_emoji: custom_emoji)
|
||||||
|
|
||||||
status.touch # rubocop:disable Rails/SkipsModelValidations
|
status.touch # rubocop:disable Rails/SkipsModelValidations
|
||||||
|
|
|
@ -19,15 +19,6 @@ RSpec.describe EmojiReactService, type: :service do
|
||||||
expect(subject.first.custom_emoji_id).to be_nil
|
expect(subject.first.custom_emoji_id).to be_nil
|
||||||
end
|
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
|
context 'when multiple reactions by same account' do
|
||||||
let(:name) { '😂' }
|
let(:name) { '😂' }
|
||||||
|
|
||||||
|
@ -139,6 +130,37 @@ RSpec.describe EmojiReactService, type: :service do
|
||||||
end
|
end
|
||||||
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
|
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') }
|
let!(:bob) { Fabricate(:account, domain: 'foo.bar', uri: 'https://foo.bar/actor', inbox_url: 'https://foo.bar/inbox', protocol: 'activitypub') }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue