Skip to content
Extraits de code Groupes Projets
status_messages_controller.rb 3,2 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!
    
      before_filter :remove_getting_started, :only => [:create]
    
      respond_to :html,
                 :mobile,
                 :json
    
      # Called when a user clicks "Mention" on a profile page
    
      # @param person_id [Integer] The id of the person to be mentioned
    
        if params[:person_id] && @person = Person.where(:id => params[:person_id]).first
    
          @aspect = :profile
          @contact = current_user.contact_for(@person)
          @aspects_with_person = []
          if @contact
            @aspects_with_person = @contact.aspects
    
            @aspect_ids = @aspects_with_person.map{|x| x.id}
    
            @contacts_of_contact = @contact.contacts
            render :layout => nil
          end
    
          @aspect = :all
          @aspects = current_user.aspects
          @aspect_ids = @aspects.map{ |a| a.id }
    
        @aspects = current_user.aspects
        @aspect_ids = @aspects.map{|x| x.id}
    
    maxwell's avatar
    maxwell a validé
      def create
    
        params[:status_message][:aspect_ids] = [*params[:aspect_ids]]
    
        services = [*params[:services]].compact
    
        @status_message = current_user.build_post(:status_message, params[:status_message])
    
        @status_message.attach_photos_by_ids(params[:photos])
    
          aspects = current_user.aspects_from_ids(destination_aspect_ids)
    
          current_user.add_to_streams(@status_message, aspects)
    
          receiving_services = current_user.services.where(:type => Service.titles(services))
    
          current_user.dispatch_post(@status_message, :url => short_post_url(@status_message.guid), :services => receiving_services)
    
    
          if coming_from_profile_page? # if this is a post coming from a profile page
            flash[:notice] = successful_mention_message
    
            format.mobile{ redirect_to multi_stream_path}
    
            format.json{ render :json => @status_message.as_api_response(:backbone), :status => 201 }
    
            format.json { render :nothing, :status => 403 }
            format.html { redirect_to :back }
    
    maxwell's avatar
    maxwell a validé
      end
    
      def destination_aspect_ids
        if params[:status_message][:public] || params[:status_message][:aspect_ids].first == "all_aspects"
          current_user.aspect_ids
        else
          params[:aspect_ids]
        end
      end
    
      def successful_mention_message
        t('status_messages.create.success', :names => @status_message.mentioned_people_names)
      end
    
      def coming_from_profile_page?
        request.env['HTTP_REFERER'].include?("people")
      end
    
    
        # mobile || desktop conditions
    
        sm = params[:status_message]
        public_flag = (sm[:aspect_ids] && sm[:aspect_ids].first == 'public') || sm[: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
    
        current_user.disable_getting_started
    
    maxwell's avatar
    maxwell a validé
    end