mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 03:57:52 +00:00
fix: Delete attachments when removing them from Instagram in real-time (#9996)
This commit is contained in:
@@ -83,6 +83,7 @@ class Instagram::MessageText < Instagram::WebhooksBaseService
|
|||||||
)
|
)
|
||||||
return if message_to_delete.blank?
|
return if message_to_delete.blank?
|
||||||
|
|
||||||
|
message_to_delete.attachments.destroy_all
|
||||||
message_to_delete.update!(content: I18n.t('conversations.messages.deleted'), deleted: true)
|
message_to_delete.update!(content: I18n.t('conversations.messages.deleted'), deleted: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -81,9 +81,7 @@ describe Webhooks::InstagramEventsJob do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'handle instagram unsend message event' do
|
it 'handle instagram unsend message event' do
|
||||||
create(:message,
|
message = create(:message, inbox_id: instagram_inbox.id, source_id: 'message-id-to-delete')
|
||||||
source_id: 'message-id-to-delete',
|
|
||||||
inbox_id: instagram_inbox.id)
|
|
||||||
allow(Koala::Facebook::API).to receive(:new).and_return(fb_object)
|
allow(Koala::Facebook::API).to receive(:new).and_return(fb_object)
|
||||||
allow(fb_object).to receive(:get_object).and_return(
|
allow(fb_object).to receive(:get_object).and_return(
|
||||||
{
|
{
|
||||||
@@ -93,10 +91,15 @@ describe Webhooks::InstagramEventsJob do
|
|||||||
profile_pic: 'https://chatwoot-assets.local/sample.png'
|
profile_pic: 'https://chatwoot-assets.local/sample.png'
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
)
|
)
|
||||||
|
message.attachments.new(file_type: :image, external_url: 'https://www.example.com/test.jpeg')
|
||||||
|
|
||||||
expect(instagram_inbox.messages.count).to be 1
|
expect(instagram_inbox.messages.count).to be 1
|
||||||
|
|
||||||
instagram_webhook.perform_now(unsend_event[:entry])
|
instagram_webhook.perform_now(unsend_event[:entry])
|
||||||
|
|
||||||
expect(instagram_inbox.messages.last.content).to eq 'This message was deleted'
|
expect(instagram_inbox.messages.last.content).to eq 'This message was deleted'
|
||||||
|
expect(instagram_inbox.messages.last.deleted).to be true
|
||||||
|
expect(instagram_inbox.messages.last.attachments.count).to be 0
|
||||||
expect(instagram_inbox.messages.last.reload.deleted).to be true
|
expect(instagram_inbox.messages.last.reload.deleted).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user