From 1faac3d431a5863b396f545b2fcfe6d41af06374 Mon Sep 17 00:00:00 2001 From: manu vasconcelos Date: Wed, 18 Dec 2024 14:30:45 -0300 Subject: [PATCH] move return back, change associated_obj to associated There aren't any changes to associated before we try to create the Relationship, so I think it's ok to do the early return earlier. We create the relationship between associated and target, not associated_obj, so we should check it instead. --- app/models/concerns/smooch_messages.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/smooch_messages.rb b/app/models/concerns/smooch_messages.rb index 9ba64b4dd..fa7ce9a2c 100644 --- a/app/models/concerns/smooch_messages.rb +++ b/app/models/concerns/smooch_messages.rb @@ -430,6 +430,7 @@ def smooch_post_save_message_actions(message, associated, app_id, author, reques end def smooch_relate_items_for_same_message(message, associated, app_id, author, request_type, associated_obj) + return unless associated.is_a?(ProjectMedia) if !message['caption'].blank? # Check if message contains caption then create an item and force relationship self.relate_item_and_text(message, associated, app_id, author, request_type, associated_obj, Relationship.confirmed_type) @@ -456,7 +457,6 @@ def relate_item_and_text(message, associated, app_id, author, request_type, asso target = self.create_project_media_from_message(message) unless target.nil? smooch_post_save_message_actions(message, target, app_id, author, request_type, associated_obj) - return unless associated_obj.is_a?(ProjectMedia) Relationship.create_unless_exists(associated.id, target.id, relationship_type) end end