feat: Ignore tweets from blocked users (#1408)
This commit is contained in:
parent
563da0e052
commit
ef99fd3311
3 changed files with 14 additions and 1 deletions
|
@ -3,7 +3,7 @@ class Twitter::TweetParserService < Twitter::WebhooksBaseService
|
|||
|
||||
def perform
|
||||
set_inbox
|
||||
return if message_already_exist?
|
||||
return if message_already_exist? || user_has_blocked?
|
||||
|
||||
create_message
|
||||
end
|
||||
|
@ -34,6 +34,10 @@ class Twitter::TweetParserService < Twitter::WebhooksBaseService
|
|||
tweet_data['id'].to_s
|
||||
end
|
||||
|
||||
def user_has_blocked?
|
||||
payload['user_has_blocked'] == true
|
||||
end
|
||||
|
||||
def parent_tweet_id
|
||||
tweet_data['in_reply_to_status_id_str'].nil? ? tweet_data['id'].to_s : tweet_data['in_reply_to_status_id_str']
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
FactoryBot.define do
|
||||
factory :tweet_create_event, class: Hash do
|
||||
for_user_id { '1' }
|
||||
user_has_blocked { false }
|
||||
tweet_create_events do
|
||||
[
|
||||
{
|
||||
|
|
|
@ -10,6 +10,7 @@ describe Webhooks::Twitter do
|
|||
let!(:twitter_inbox) { create(:inbox, channel: twitter_channel, account: account, greeting_enabled: false) }
|
||||
let!(:dm_params) { build(:twitter_message_create_event).with_indifferent_access }
|
||||
let!(:tweet_params) { build(:tweet_create_event).with_indifferent_access }
|
||||
let!(:tweet_params_from_blocked_user) { build(:tweet_create_event, user_has_blocked: true).with_indifferent_access }
|
||||
|
||||
describe '#perform' do
|
||||
context 'with direct_message params' do
|
||||
|
@ -22,6 +23,13 @@ describe Webhooks::Twitter do
|
|||
end
|
||||
|
||||
context 'with tweet_params params' do
|
||||
it 'does not create incoming message in the twitter inbox if it is a blocked user' do
|
||||
twitter_webhook.new(tweet_params_from_blocked_user).consume
|
||||
expect(twitter_inbox.contacts.count).to be 0
|
||||
expect(twitter_inbox.conversations.count).to be 0
|
||||
expect(twitter_inbox.messages.count).to be 0
|
||||
end
|
||||
|
||||
it 'creates incoming message in the twitter inbox' do
|
||||
twitter_webhook.new(tweet_params).consume
|
||||
expect(twitter_inbox.contacts.count).to be 1
|
||||
|
|
Loading…
Reference in a new issue