Skip to content
Extraits de code Groupes Projets
status_messages_controller.rb 3,02 ko
Newer Older
  • Learn to ignore specific revisions
  • danielgrippi's avatar
    danielgrippi a validé
    #   Copyright (c) 2010-2011, Diaspora Inc.  This file is
    
    Raphael's avatar
    Raphael a validé
    #   licensed under the Affero General Public License version 3 or later.  See
    
    Raphael's avatar
    Raphael a validé
    #   the COPYRIGHT file.
    
    maxwell's avatar
    maxwell a validé
    class StatusMessagesController < ApplicationController
    
      before_filter :authenticate_user!
    
      # Called when a user clicks "Mention" on a profile page
      # @option [Integer] person_id The id of the person to be mentioned
    
      def new
        @person = Person.find(params[:person_id])
        @aspect = :profile
        @contact = current_user.contact_for(@person)
        @aspects_with_person = []
        if @contact
          @aspects_with_person = @contact.aspects
          @aspect_ids = @aspects_with_person.map(&:id)
          @contacts_of_contact = @contact.contacts
    
          render :layout => nil
        else
          redirect_to :back
        end
      end
    
    
        @aspects = current_user.aspects
    
        @selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq
    
        @aspect_ids = @aspects.map{|x| x.id}
        render :layout => nil
      end
    
    
    maxwell's avatar
    maxwell a validé
      def create
    
        params[:status_message][:aspect_ids] = params[:aspect_ids]
    
        @status_message = current_user.build_post(:status_message, params[:status_message])
    
        photos = Photo.where(:id => [*params[:photos]], :diaspora_handle => current_user.person.diaspora_handle)
        unless photos.empty?
          @status_message.photos << photos
        end
    
    
          Rails.logger.info("event=create type=status_message chars=#{params[:status_message][:text].length}")
    
          aspects = current_user.aspects_from_ids(params[:aspect_ids])
          current_user.add_to_streams(@status_message, aspects)
    
          receiving_services = current_user.services.where(:type => params[:services].map{|s| "Services::"+s.titleize}) if params[:services]
    
          current_user.dispatch_post(@status_message, :url => short_post_url(@status_message.guid), :services => receiving_services)
    
    
          if request.env['HTTP_REFERER'].include?("people") # if this is a post coming from a profile page
    
    MrZYX's avatar
    MrZYX a validé
            flash[:notice] = t('status_messages.create.success', :names => @status_message.mentions.includes(:person => :profile).map{ |mention| mention.person.name }.join(', '))
    
            format.js { render :create, :status => 201}
    
            format.mobile{ redirect_to root_url}
    
          unless photos.empty?
            photos.update_all(:status_message_guid => nil)
          end
    
              errors = @status_message.errors.full_messages.collect { |msg| msg.gsub(/^Text/, "") }
              render :json =>{:errors => errors}, :status => 422
            }
    
            format.html {redirect_to :back}
    
    maxwell's avatar
    maxwell a validé
      end
    
      def normalize_public_flag!
        public_flag = params[:status_message][:public]
        public_flag.to_s.match(/(true)|(on)/) ? public_flag = true : public_flag = false
        params[:status_message][:public] = public_flag
        public_flag
    
    maxwell's avatar
    maxwell a validé
      end
    
      helper_method :comments_expanded
      def comments_expanded
        true
      end
    
    maxwell's avatar
    maxwell a validé
    end