Skip to content
Extraits de code Groupes Projets
contacts_controller.rb 2,03 ko
Newer Older
  • Learn to ignore specific revisions
  • danielgrippi's avatar
    danielgrippi a validé
    #   Copyright (c) 2010-2011, Diaspora Inc.  This file is
    
    #   licensed under the Affero General Public License version 3 or later.  See
    #   the COPYRIGHT file.
    
    class ContactsController < ApplicationController
    
      before_action :authenticate_user!
    
    Raphael Sofaer's avatar
    Raphael Sofaer a validé
      def index
    
        respond_to do |format|
    
          # Used for normal requests to contacts#index
    
          format.mobile { set_up_contacts_mobile }
    
    Raphael Sofaer's avatar
    Raphael Sofaer a validé
    
    
          # Used for mentions in the publisher
          format.json {
            @people = Person.search(params[:q], current_user, only_contacts: true).limit(15)
    
            render json: @people
    
      def spotlight
        @spotlight = true
        @people = Person.community_spotlight
    
        type = params[:set].presence
        type ||= "by_aspect" if params[:a_id].present?
        type ||= "receiving"
    
        @contacts = contacts_by_type(type)
        @contacts_size = @contacts.length
    
        gon.preloads[:contacts] = @contacts.map {|c| ContactPresenter.new(c, current_user).full_hash_with_person }
    
      end
    
      def contacts_by_type(type)
    
            current_user.contacts
    
          when "only_sharing"
    
            current_user.contacts.only_sharing
    
          when "receiving"
    
            current_user.contacts.receiving
    
          when "by_aspect"
            @aspect = current_user.aspects.find(params[:a_id])
    
            gon.preloads[:aspect] = AspectPresenter.new(@aspect).as_json
            current_user.contacts
    
            raise ArgumentError, "unknown type #{type}"
          end
    
      def set_up_contacts_mobile
    
        @contacts = case params[:set]
          when "only_sharing"
            current_user.contacts.only_sharing
          when "all"
            current_user.contacts
          else
            if params[:a_id]
              @aspect = current_user.aspects.find(params[:a_id])
              @aspect.contacts
            else
              current_user.contacts.receiving
            end
        end
        @contacts = @contacts.for_a_stream.paginate(:page => params[:page], :per_page => 25)
    
        @contacts_size = @contacts.length