diff --git a/app/builders/messages/message_builder.rb b/app/builders/messages/message_builder.rb index ba78d76d77c9..b6ae5409d90b 100644 --- a/app/builders/messages/message_builder.rb +++ b/app/builders/messages/message_builder.rb @@ -15,21 +15,25 @@ def initialize(user, conversation, params) def perform @message = @conversation.messages.build(message_params) - if @attachments.present? - @attachments.each do |uploaded_attachment| - attachment = @message.attachments.new( - account_id: @message.account_id, - file_type: file_type(uploaded_attachment&.content_type) - ) - attachment.file.attach(uploaded_attachment) - end - end - @message.save + process_attachments + @message.save! @message end private + def process_attachments + return if @attachments.blank? + + @attachments.each do |uploaded_attachment| + @message.attachments.build( + account_id: @message.account_id, + file_type: file_type(uploaded_attachment&.content_type), + file: uploaded_attachment + ) + end + end + def message_type if @conversation.inbox.channel_type != 'Channel::Api' && @message_type == 'incoming' raise StandardError, 'Incoming messages are only allowed in Api inboxes' diff --git a/app/controllers/api/v1/widget/messages_controller.rb b/app/controllers/api/v1/widget/messages_controller.rb index 9e6f770ad86b..0d9ab6323077 100644 --- a/app/controllers/api/v1/widget/messages_controller.rb +++ b/app/controllers/api/v1/widget/messages_controller.rb @@ -8,8 +8,8 @@ def index def create @message = conversation.messages.new(message_params) - @message.save build_attachment + @message.save! end def update @@ -29,13 +29,12 @@ def build_attachment return if params[:message][:attachments].blank? params[:message][:attachments].each do |uploaded_attachment| - attachment = @message.attachments.new( + @message.attachments.new( account_id: @message.account_id, - file_type: helpers.file_type(uploaded_attachment&.content_type) + file_type: helpers.file_type(uploaded_attachment&.content_type), + file: uploaded_attachment ) - attachment.file.attach(uploaded_attachment) end - @message.save! end def set_conversation diff --git a/app/controllers/public/api/v1/inboxes/messages_controller.rb b/app/controllers/public/api/v1/inboxes/messages_controller.rb index 68c0f5223e47..925c16d38433 100644 --- a/app/controllers/public/api/v1/inboxes/messages_controller.rb +++ b/app/controllers/public/api/v1/inboxes/messages_controller.rb @@ -7,8 +7,8 @@ def index def create @message = @conversation.messages.new(message_params) - @message.save build_attachment + @message.save! end def update @@ -23,13 +23,12 @@ def build_attachment return if params[:attachments].blank? params[:attachments].each do |uploaded_attachment| - attachment = @message.attachments.new( + @message.attachments.new( account_id: @message.account_id, - file_type: helpers.file_type(uploaded_attachment&.content_type) + file_type: helpers.file_type(uploaded_attachment&.content_type), + file: uploaded_attachment ) - attachment.file.attach(uploaded_attachment) end - @message.save! end def message_finder_params diff --git a/app/helpers/file_type_helper.rb b/app/helpers/file_type_helper.rb index 4936fa155ddf..64d67701a0d2 100644 --- a/app/helpers/file_type_helper.rb +++ b/app/helpers/file_type_helper.rb @@ -3,12 +3,12 @@ def file_type(content_type) return :image if [ 'image/jpeg', 'image/png', - 'image/svg+xml', 'image/gif', 'image/tiff', 'image/bmp' ].include?(content_type) + return :video if content_type.include?('video/') return :audio if content_type.include?('audio/') :file diff --git a/app/javascript/dashboard/components/widgets/WootWriter/ReplyBottomPanel.vue b/app/javascript/dashboard/components/widgets/WootWriter/ReplyBottomPanel.vue index 1ffb09e04275..1ffc9be6538c 100644 --- a/app/javascript/dashboard/components/widgets/WootWriter/ReplyBottomPanel.vue +++ b/app/javascript/dashboard/components/widgets/WootWriter/ReplyBottomPanel.vue @@ -11,10 +11,11 @@ @click="toggleEmojiPicker" /> + +