fix: added additional attributes filter and refactored conversation logic in Instagram message builder
This commit is contained in:
@@ -71,19 +71,14 @@ class Messages::Instagram::MessageBuilder < Messages::Messenger::MessageBuilder
|
||||
def conversation
|
||||
@conversation ||= begin
|
||||
lock_to_single_conversation = @inbox.lock_to_single_conversation
|
||||
conversations = Conversation.where(conversation_params)
|
||||
.where("additional_attributes ->> 'type' = 'instagram_direct_message'")
|
||||
|
||||
if lock_to_single_conversation
|
||||
Conversation.where(conversation_params).find_by(
|
||||
"additional_attributes ->> 'type' = 'instagram_direct_message'"
|
||||
) || build_conversation
|
||||
conversations.find_by || build_conversation
|
||||
else
|
||||
# If lock to single conversation is disabled, we will create a new conversation if previous conversation is resolved
|
||||
last_conversation = Conversation.where(conversation_params).order(created_at: :desc).first
|
||||
if last_conversation&.status == 'resolved'
|
||||
build_conversation
|
||||
else
|
||||
last_conversation
|
||||
end
|
||||
last_conversation = conversations.order(created_at: :desc).first
|
||||
last_conversation&.status == 'resolved' ? build_conversation : last_conversation || build_conversation
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user