From 84f6cadae7c839f6d1a57dfc8fe83fbb26dbf5a4 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Thu, 8 Feb 2024 21:12:55 +0400 Subject: [PATCH] chore: Remove unused builders for widget (#8876) - These builders are not used in our code base, hence removing them --- .../widget/incoming_message_builder.rb | 58 ------------------- .../widget/outgoing_message_builder.rb | 52 ----------------- 2 files changed, 110 deletions(-) delete mode 100644 lib/integrations/widget/incoming_message_builder.rb delete mode 100644 lib/integrations/widget/outgoing_message_builder.rb diff --git a/lib/integrations/widget/incoming_message_builder.rb b/lib/integrations/widget/incoming_message_builder.rb deleted file mode 100644 index 82bc303f35c4..000000000000 --- a/lib/integrations/widget/incoming_message_builder.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -class Integrations::Widget::IncomingMessageBuilder - # params = { - # contact_id: 1, - # inbox_id: 1, - # content: "Hello world" - # } - - attr_accessor :options, :message - - def initialize(options) - @options = options - end - - def perform - ActiveRecord::Base.transaction do - build_message - end - end - - private - - def inbox - @inbox ||= Inbox.find(options[:inbox_id]) - end - - def contact - @contact ||= Contact.find(options[:contact_id]) - end - - def conversation - @conversation ||= Conversation.find_by(conversation_params) || Conversation.create!(conversation_params) - end - - def build_message - @message = conversation.messages.new(message_params) - @message.save! - end - - def conversation_params - { - account_id: inbox.account_id, - inbox_id: inbox.id, - contact_id: options[:contact_id] - } - end - - def message_params - { - account_id: conversation.account_id, - inbox_id: conversation.inbox_id, - message_type: 0, - content: options[:content], - sender: contact - } - end -end diff --git a/lib/integrations/widget/outgoing_message_builder.rb b/lib/integrations/widget/outgoing_message_builder.rb deleted file mode 100644 index c209f3fc19a2..000000000000 --- a/lib/integrations/widget/outgoing_message_builder.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true - -class Integrations::Widget::OutgoingMessageBuilder - # params = { - # user_id: 1, - # inbox_id: 1, - # content: "Hello world", - # conversation_id: 2 - # } - - attr_accessor :options, :message - - def initialize(options) - @options = options - end - - def perform - ActiveRecord::Base.transaction do - conversation - build_message - end - end - - private - - def inbox - @inbox ||= Inbox.find(options[:inbox_id]) - end - - def user - @user ||= Contact.find(options[:user_id]) - end - - def conversation - @conversation ||= Conversation.find(options[:conversation_id]) - end - - def build_message - @message = conversation.messages.new(message_params) - @message.save! - end - - def message_params - { - account_id: conversation.account_id, - inbox_id: conversation.inbox_id, - message_type: 1, - content: options[:content], - sender: user - } - end -end