Skip to content
Extraits de code Groupes Projets
messages_controller.rb 914 octets
Newer Older
  • Learn to ignore specific revisions
  • danielgrippi's avatar
    danielgrippi a validé
    #   Copyright (c) 2010-2011, Diaspora Inc.  This file is
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
    #   licensed under the Affero General Public License version 3 or later.  See
    #   the COPYRIGHT file.
    
    class MessagesController < ApplicationController
    
      before_action :authenticate_user!
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
    
      respond_to :html, :mobile
      respond_to :json, :only => :show
    
      def create
    
    Gonzalo's avatar
    Gonzalo a validé
        conversation = Conversation.find(params[:conversation_id])
    
        opts = params.require(:message).permit(:text)
        message = current_user.build_message(conversation, opts)
    
    Gonzalo's avatar
    Gonzalo a validé
    
        if message.save
          Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success message=#{message.id} chars=#{params[:message][:text].length}")
          Postzord::Dispatcher.build(current_user, message).post
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
        else
    
          flash[:error] = I18n.t('conversations.new_conversation.fail')
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
        end
    
    Gonzalo's avatar
    Gonzalo a validé
        redirect_to conversations_path(:conversation_id => conversation.id)
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
      end
    end