feat: Ability to lock the conversation to a single thread in API channels (#10329)
Added the possibility to mark as a single conversation in the API type inbox. This allows the conversation builder to search for the last conversation. I thought about searching for the last conversation with created_at: desc order, as is done in some channels... but I didn't change the way the conversation is searched. Fixes: #7726 Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -175,7 +175,10 @@ export default {
|
||||
},
|
||||
canLocktoSingleConversation() {
|
||||
return (
|
||||
this.isASmsInbox || this.isAWhatsAppChannel || this.isAFacebookInbox
|
||||
this.isASmsInbox ||
|
||||
this.isAWhatsAppChannel ||
|
||||
this.isAFacebookInbox ||
|
||||
this.isAPIInbox
|
||||
);
|
||||
},
|
||||
inboxNameLabel() {
|
||||
|
||||
@@ -3,39 +3,77 @@ require 'rails_helper'
|
||||
describe ConversationBuilder do
|
||||
let(:account) { create(:account) }
|
||||
let!(:sms_channel) { create(:channel_sms, account: account) }
|
||||
let!(:api_channel) { create(:channel_api, account: account) }
|
||||
let!(:sms_inbox) { create(:inbox, channel: sms_channel, account: account) }
|
||||
let!(:api_inbox) { create(:inbox, channel: api_channel, account: account) }
|
||||
let(:contact) { create(:contact, account: account) }
|
||||
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: sms_inbox) }
|
||||
let(:contact_sms_inbox) { create(:contact_inbox, contact: contact, inbox: sms_inbox) }
|
||||
let(:contact_api_inbox) { create(:contact_inbox, contact: contact, inbox: api_inbox) }
|
||||
|
||||
describe '#perform' do
|
||||
it 'creates conversation' do
|
||||
it 'creates sms conversation' do
|
||||
conversation = described_class.new(
|
||||
contact_inbox: contact_inbox,
|
||||
contact_inbox: contact_sms_inbox,
|
||||
params: {}
|
||||
).perform
|
||||
|
||||
expect(conversation.contact_inbox_id).to eq(contact_inbox.id)
|
||||
expect(conversation.contact_inbox_id).to eq(contact_sms_inbox.id)
|
||||
end
|
||||
|
||||
context 'when lock_to_single_conversation is true for inbox' do
|
||||
it 'creates api conversation' do
|
||||
conversation = described_class.new(
|
||||
contact_inbox: contact_api_inbox,
|
||||
params: {}
|
||||
).perform
|
||||
|
||||
expect(conversation.contact_inbox_id).to eq(contact_api_inbox.id)
|
||||
end
|
||||
|
||||
context 'when lock_to_single_conversation is true for sms inbox' do
|
||||
before do
|
||||
sms_inbox.update!(lock_to_single_conversation: true)
|
||||
end
|
||||
|
||||
it 'creates conversation when existing conversation is not present' do
|
||||
it 'creates sms conversation when existing conversation is not present' do
|
||||
conversation = described_class.new(
|
||||
contact_inbox: contact_inbox,
|
||||
contact_inbox: contact_sms_inbox,
|
||||
params: {}
|
||||
).perform
|
||||
|
||||
expect(conversation.contact_inbox_id).to eq(contact_inbox.id)
|
||||
expect(conversation.contact_inbox_id).to eq(contact_sms_inbox.id)
|
||||
end
|
||||
|
||||
it 'returns last from existing conversations when existing conversation is not present' do
|
||||
create(:conversation, contact_inbox: contact_inbox)
|
||||
existing_conversation = create(:conversation, contact_inbox: contact_inbox)
|
||||
it 'returns last from existing sms conversations when existing conversation is not present' do
|
||||
create(:conversation, contact_inbox: contact_sms_inbox)
|
||||
existing_conversation = create(:conversation, contact_inbox: contact_sms_inbox)
|
||||
conversation = described_class.new(
|
||||
contact_inbox: contact_inbox,
|
||||
contact_inbox: contact_sms_inbox,
|
||||
params: {}
|
||||
).perform
|
||||
|
||||
expect(conversation.id).to eq(existing_conversation.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when lock_to_single_conversation is true for api inbox' do
|
||||
before do
|
||||
api_inbox.update!(lock_to_single_conversation: true)
|
||||
end
|
||||
|
||||
it 'creates conversation when existing api conversation is not present' do
|
||||
conversation = described_class.new(
|
||||
contact_inbox: contact_api_inbox,
|
||||
params: {}
|
||||
).perform
|
||||
|
||||
expect(conversation.contact_inbox_id).to eq(contact_api_inbox.id)
|
||||
end
|
||||
|
||||
it 'returns last from existing api conversations when existing conversation is not present' do
|
||||
create(:conversation, contact_inbox: contact_api_inbox)
|
||||
existing_conversation = create(:conversation, contact_inbox: contact_api_inbox)
|
||||
conversation = described_class.new(
|
||||
contact_inbox: contact_api_inbox,
|
||||
params: {}
|
||||
).perform
|
||||
|
||||
|
||||
Reference in New Issue
Block a user