diff --git a/lib/twitter_sync.rb b/lib/twitter_sync.rb index e99bccc43..d0850fc16 100644 --- a/lib/twitter_sync.rb +++ b/lib/twitter_sync.rb @@ -704,6 +704,7 @@ process webhook messages from twitter if @payload['tweet_create_events'].present? @payload['tweet_create_events'].each do |item| next if Ticket::Article.exists?(message_id: item['id']) + next if item.key?('retweeted_status') && !channel.options.dig('sync', 'track_retweets') # check if it's mention group_id = nil diff --git a/spec/models/channel/driver/twitter_spec.rb b/spec/models/channel/driver/twitter_spec.rb index b7e4e0054..56ff4ff5a 100644 --- a/spec/models/channel/driver/twitter_spec.rb +++ b/spec/models/channel/driver/twitter_spec.rb @@ -568,6 +568,35 @@ RSpec.describe Channel::Driver::Twitter do expect(Ticket::Article.last.attachments).to be_one end end + + context 'when message is a retweet' do + let(:payload_file) { Rails.root.join('test/data/twitter/webhook_events/tweet_create-retweet.yml') } + + context 'and "conversion of retweets" is enabled' do + before do + channel.options['sync']['track_retweets'] = true + channel.save + end + + it 'creates a new article' do + expect { channel.process(payload) } + .to change(Ticket::Article, :count).by(1) + .and change { Ticket::Article.exists?(article_attributes) }.to(true) + end + end + + context 'and "conversion of retweets" is disabled' do + before do + channel.options['sync']['track_retweets'] = false + channel.save + end + + it 'does not create a new article' do + expect { channel.process(payload) } + .not_to change(Ticket::Article, :count) + end + end + end end end