Class: PeopleController

Inherits:
ApplicationController show all
Includes:
GonHelper
Defined in:
app/controllers/people_controller.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Instance Method Summary collapse

Methods included from GonHelper

#gon_load_contact

Instance Method Details

#hovercardObject

hovercards fetch some the persons public profile data via json and display it next to the avatar image in a nice box


104
105
106
107
108
109
110
111
112
113
114
# File 'app/controllers/people_controller.rb', line 104

def hovercard
  respond_to do |format|
    format.all do
      redirect_to :action => "show", :id => params[:person_id]
    end

    format.json do
      render json: PersonPresenter.new(@person, current_user).hovercard
    end
  end
end

#indexObject


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/people_controller.rb', line 31

def index
  @aspect = :search
  limit = params[:limit] ? params[:limit].to_i : 15

  @people = Person.search(search_query, current_user)

  respond_to do |format|
    format.json do
      @people = @people.limit(limit)
      render :json => @people
    end

    format.any(:html, :mobile) do
      # only do it if it is a diaspora*-ID
      if diaspora_id?(search_query)
        @people = Person.where(diaspora_handle: search_query.downcase, closed_account: false)
        background_search(search_query) if @people.empty?
      end
      @people = @people.paginate(:page => params[:page], :per_page => 15)
      @hashes = hashes_for_people(@people, @aspects)
    end
  end
end

#refresh_searchObject


55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/people_controller.rb', line 55

def refresh_search
  @aspect = :search
  @people = Person.where(diaspora_handle: search_query.downcase, closed_account: false)
  @answer_html = ""
  unless @people.empty?
    @hashes = hashes_for_people(@people, @aspects)

    self.formats = self.formats + [:html]
    @answer_html = render_to_string :partial => 'people/person', :locals => @hashes.first
  end
  render json: {search_html: @answer_html, contacts: gon.preloads[:contacts]}.to_json
end

#retrieve_remoteObject


116
117
118
119
120
121
122
123
# File 'app/controllers/people_controller.rb', line 116

def retrieve_remote
  if params[:diaspora_handle]
    Workers::FetchWebfinger.perform_async(params[:diaspora_handle])
    head :ok
  else
    head :unprocessable_entity
  end
end

#showObject

renders the persons user profile page


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/people_controller.rb', line 69

def show
  mark_corresponding_notifications_read if user_signed_in?
  @presenter = PersonPresenter.new(@person, current_user)

  respond_to do |format|
    format.all do
      if user_signed_in?
        @contact = current_user.contact_for(@person)
      end
      gon.preloads[:person] = @presenter.as_json
      gon.preloads[:photos_count] = Photo.visible(current_user, @person).count(:all)
      respond_with @presenter, layout: "with_header"
    end

    format.mobile do
      @post_type = :all
      person_stream
      respond_with @presenter
    end

    format.json { render json: @presenter.as_json }
  end
end

#streamObject


93
94
95
96
97
98
99
100
# File 'app/controllers/people_controller.rb', line 93

def stream
  respond_to do |format|
    format.all { redirect_to person_path(@person) }
    format.json {
      render json: person_stream.stream_posts.map { |p| LastThreeCommentsDecorator.new(PostPresenter.new(p, current_user)) }
    }
  end
end