<commit_before>class MessagesController < ApplicationController
  before_action :authenticate_user!, :only => [:create]
  
  def create
    find_account!

    action = CommandBarAction.new(message_params)

    if action.save
      Analytics.track(
        user_id: current_user.id,
        event: 'New Message',
        properties: { action: params['commit'] }
      )

      if params['commit'] == "Archive"
        action.conversation.archive!
        flash[:notice] = "The conversation has been archived and the message sent."
        redirect_to inbox_account_conversations_path(@account)
      else
        redirect_to account_conversation_path(@account, action.conversation)
      end

    else
      if params['commit'] == "Archive" && message_params['content'].empty?
        action.conversation.archive!
        redirect_to inbox_account_conversations_path(@account)
      else
        Analytics.track(user_id: current_user.id, event: 'Message Save Problem')
        redirect_to account_conversation_path(@account, action.conversation), alert: "Problem"
      end
    end
  end

  private

  def find_account!
    @account = Account.find_by_slug!(params.fetch(:account_id))
  end

  def message_params
    params.require(:message).permit(
      :content, :conversation_id
    ).merge(
      person_id: current_user.person.id
    )
  end<commit_msg>Add notice<commit_after>class MessagesController < ApplicationController
  before_action :authenticate_user!, :only => [:create]
  
  def create
    find_account!

    action = CommandBarAction.new(message_params)

    if action.save
      Analytics.track(
        user_id: current_user.id,
        event: 'New Message',
        properties: { action: params['commit'] }
      )

      if params['commit'] == "Archive"
        action.conversation.archive!
        flash[:notice] = "The conversation has been archived and the message sent."
        redirect_to inbox_account_conversations_path(@account)
      else
        redirect_to account_conversation_path(@account, action.conversation)
      end

    else
      if params['commit'] == "Archive" && message_params['content'].empty?
        action.conversation.archive!
        flash[:notice] = "The conversation has been archived."
        redirect_to inbox_account_conversations_path(@account)
      else
        Analytics.track(user_id: current_user.id, event: 'Message Save Problem')
        redirect_to account_conversation_path(@account, action.conversation), alert: "Problem"
      end
    end
  end

  private

  def find_account!
    @account = Account.find_by_slug!(params.fetch(:account_id))
  end

  def message_params
    params.require(:message).permit(
      :content, :conversation_id
    ).merge(
      person_id: current_user.person.id
    )
  end
{'fraction_non_alphanumeric': 0.0962509012256669, 'fraction_numerical': 0.0, 'mean_word_length': 3.1666666666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '959877', 'n_tokens_mistral': 809, 'n_tokens_neox': 782, 'n_words': 170}