Skip to content

Commit

Permalink
Fix: #172 他のサーバーからの相乗り絵文字削除が反映されない
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Oct 23, 2023
1 parent 10fec60 commit 3ce7537
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
7 changes: 6 additions & 1 deletion app/lib/activitypub/activity/undo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ def undo_like
if shortcode.present?
emoji_tag = @object['tag'].is_a?(Array) ? @object['tag']&.first : @object['tag']

emoji = CustomEmoji.find_by(shortcode: shortcode, domain: @account.domain) if emoji_tag.present? && emoji_tag['id'].present?
emoji = nil
if emoji_tag.present? && emoji_tag['id'].present?
domain = URI.split(emoji_tag['id'])[2]
domain = nil if domain == Rails.configuration.x.local_domain || domain == Rails.configuration.x.web_domain
emoji = CustomEmoji.find_by(shortcode: shortcode, domain: domain) if emoji_tag.present? && emoji_tag['id'].present?
end

emoji_reaction = @original_status.emoji_reactions.where(account: @account, name: shortcode, custom_emoji: emoji).first

Expand Down
60 changes: 56 additions & 4 deletions spec/lib/activitypub/activity/undo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
RSpec.describe ActivityPub::Activity::Undo do
subject { described_class.new(json, sender) }

let(:sender) { Fabricate(:account, domain: 'example.com') }
let(:sender_domain) { 'example.com' }
let(:sender) { Fabricate(:account, domain: sender_domain) }

let(:json) do
{
Expand Down Expand Up @@ -218,27 +219,78 @@
let(:status) { Fabricate(:status) }

let(:content) { '😀' }
let(:name) { '😀' }
let(:tag) { nil }
let(:object_json) do
{
id: 'bar',
type: 'Like',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: ActivityPub::TagManager.instance.uri_for(status),
content: content,
tag: tag,
}
end
let(:custom_emoji) { nil }

before do
Fabricate(:favourite, account: sender, status: status)
Fabricate(:emoji_reaction, account: sender, status: status, name: content)
Fabricate(:emoji_reaction, account: sender, status: status, name: name, custom_emoji: custom_emoji)
end

it 'delete emoji reaction' do
subject.perform
reaction = EmojiReaction.find_by(account: sender, status: status)
expect(reaction).to be_nil
expect(sender.emoji_reacted?(status)).to be false
expect(sender.favourited?(status)).to be true
end

context 'with custom emoji' do
let(:content) { ':tinking:' }
let(:name) { 'tinking' }
let(:tag) do
{
id: custom_emoji_uri,
type: 'Emoji',
icon: {
url: 'http://example.com/emoji.png',
},
name: name,
}
end
let(:custom_emoji_domain) { 'example.com' }
let(:custom_emoji_uri) { "https://#{custom_emoji_domain}/aaa" }
let(:custom_emoji) { Fabricate(:custom_emoji, uri: custom_emoji_uri, domain: custom_emoji_domain, shortcode: name) }

it 'delete emoji reaction' do
subject.perform
expect(sender.emoji_reacted?(status)).to be false
expect(sender.favourited?(status)).to be true
end

context 'when third server' do
let(:sender_domain) { 'foo.bar' }

it 'delete emoji reaction' do
subject.perform
expect(sender.emoji_reacted?(status)).to be false
expect(sender.favourited?(status)).to be true
end
end

context 'when local' do
let(:custom_emoji_domain) { 'cb6e6126.ngrok.io' }

before do
custom_emoji.update(domain: nil, uri: nil)
end

it 'delete emoji reaction' do
subject.perform
expect(sender.emoji_reacted?(status)).to be false
expect(sender.favourited?(status)).to be true
end
end
end
end
end
end

0 comments on commit 3ce7537

Please sign in to comment.