From bd4c1f5169c6697eb190ad9c16e9e34b2526078e Mon Sep 17 00:00:00 2001 From: Caio Almeida <117518+caiosba@users.noreply.github.com> Date: Thu, 5 Dec 2024 08:54:58 -0300 Subject: [PATCH] "Unsubscribe" the user from the newsletter language, not the current language. (#2150) When a tipline user is interacting with the bot in a certain language but clicks on the "Unsubscribe" button from a newsletter, the affected subscription should be the one related to the newsletter language, not the current language. So, the first here is to use the language stored in the delivered message reference, not the current language, which is still used as a fallback. Fixes: CV2-5252. --- app/models/concerns/smooch_resend.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/smooch_resend.rb b/app/models/concerns/smooch_resend.rb index 32aeab336..ea96af55a 100644 --- a/app/models/concerns/smooch_resend.rb +++ b/app/models/concerns/smooch_resend.rb @@ -118,7 +118,7 @@ def get_information_from_clicked_template_button(message, delete = false) info = Rails.cache.read("smooch:original:#{quoted_id}").to_s begin original = JSON.parse(info) - info = ['newsletter'] if original['fallback_template'] == 'newsletter' + info = ['newsletter', original['language']] if original['fallback_template'] == 'newsletter' rescue info = info.split(':') end @@ -138,6 +138,7 @@ def template_button_click_callback(message, uid, language) self.send_message_on_template_button_click(message, uid, language, info) when 'newsletter' team_id = self.config['team_id'].to_i + language = info[1] || language self.toggle_subscription(uid, language, team_id, self.get_platform_from_message(message), self.get_workflow(language)) if self.user_is_subscribed_to_newsletter?(uid, language, team_id) end end