2020-06-07 08:28:05 +00:00
|
|
|
class Api::V1::Accounts::Conversations::MessagesController < Api::V1::Accounts::Conversations::BaseController
|
2020-03-08 16:38:25 +00:00
|
|
|
def index
|
|
|
|
@messages = message_finder.perform
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
def create
|
2021-04-15 09:43:01 +00:00
|
|
|
user = Current.user || @resource
|
2020-07-21 06:45:24 +00:00
|
|
|
mb = Messages::MessageBuilder.new(user, @conversation, params)
|
2019-08-14 09:48:44 +00:00
|
|
|
@message = mb.perform
|
2020-07-21 06:45:24 +00:00
|
|
|
rescue StandardError => e
|
|
|
|
render_could_not_create_error(e.message)
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
2020-03-08 16:38:25 +00:00
|
|
|
|
2020-12-28 18:06:50 +00:00
|
|
|
def destroy
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
message.update!(content: I18n.t('conversations.messages.deleted'), deleted: true)
|
|
|
|
message.attachments.destroy_all
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-08 16:38:25 +00:00
|
|
|
private
|
|
|
|
|
2020-12-28 18:06:50 +00:00
|
|
|
def message
|
|
|
|
@message ||= @conversation.messages.find(permitted_params[:id])
|
|
|
|
end
|
|
|
|
|
2020-03-08 16:38:25 +00:00
|
|
|
def message_finder
|
|
|
|
@message_finder ||= MessageFinder.new(@conversation, params)
|
|
|
|
end
|
2020-12-28 18:06:50 +00:00
|
|
|
|
|
|
|
def permitted_params
|
|
|
|
params.permit(:id)
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|