Class: PeopleController

Inherits:
ApplicationController show all
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

Instance Method Details

#aspect_membership_dropdownObject

shows the dropdown list of aspects the current user has set for the given person. renders “thats you” in case the current user views himself


160
161
162
163
164
165
166
167
168
169
# File 'app/controllers/people_controller.rb', line 160

def aspect_membership_dropdown
  @person = Person.find_by_guid(params[:person_id])

  # you are not a contact of yourself...
  return render :text => I18n.t('people.person.thats_you') if @person == current_user.person

  @contact = current_user.contact_for(@person) || Contact.new
  bootstrap = params[:bootstrap] || false
  render :partial => 'aspect_membership_dropdown', :locals => {:contact => @contact, :person => @person, :hang => 'left', :bootstrap => bootstrap}
end

#contactsObject


144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'app/controllers/people_controller.rb', line 144

def contacts
  @person = Person.find_by_guid(params[:person_id])
  if @person
    @contact = current_user.contact_for(@person)
    @aspect = :profile
    @contacts_of_contact = @contact.contacts.paginate(:page => params[:page], :per_page => (params[:limit] || 15))
    @contacts_of_contact_count = @contact.contacts.count
    @hashes = hashes_for_people @contacts_of_contact, @aspects
  else
    flash[:error] = I18n.t 'people.show.does_not_exist'
    redirect_to people_path
  end
end

#hovercardObject

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


114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'app/controllers/people_controller.rb', line 114

def hovercard
  @person = Person.find_from_guid_or_username({:id => params[:person_id]})
  raise Diaspora::AccountClosed if @person.closed_account?

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

    format.json do
      render :json => HovercardPresenter.new(@person)
    end
  end
end

#indexObject


28
29
30
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 28

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 an email address
      if diaspora_id?(search_query)
        @people =  Person.where(:diaspora_handle => search_query.downcase)
        if @people.empty?
          Webfinger.in_background(search_query)
          @background_query = search_query.downcase
        end
      end
      @people = @people.paginate(:page => params[:page], :per_page => 15)
      @hashes = hashes_for_people(@people, @aspects)
    end
  end
end

#last_postObject


129
130
131
132
133
# File 'app/controllers/people_controller.rb', line 129

def last_post
  @person = Person.find_from_guid_or_username(params)
  last_post = Post.visible_from_author(@person, current_user).order('posts.created_at DESC').first
  redirect_to post_path(last_post)
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)
  @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_count => @people.count, :search_html => @answer_html }.to_json
end

#retrieve_remoteObject


135
136
137
138
139
140
141
142
# File 'app/controllers/people_controller.rb', line 135

def retrieve_remote
  if params[:diaspora_handle]
    Webfinger.in_background(params[:diaspora_handle], :single_aspect_form => true)
    render :nothing => true
  else
    render :nothing => true, :status => 422
  end
end

#showObject

renders the persons user profile page


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/controllers/people_controller.rb', line 76

def show
  @person = Person.find_from_guid_or_username(params)

  authenticate_user! if remote_profile_with_no_user_session?
  raise Diaspora::AccountClosed if @person.closed_account?

  mark_corresponding_notifications_read if user_signed_in?

  @post_type = :all
  @aspect = :profile
  @stream = Stream::Person.new(current_user, @person, :max_time => max_time)
  @profile = @person.profile
  @photos = photos_from(@person)

  unless params[:format] == "json" # hovercard
    if current_user
      @block = current_user.blocks.where(:person_id => @person.id).first
      @contact = current_user.contact_for(@person)
      if @contact && !params[:only_posts]
        @contacts_of_contact_count = @contact.contacts.count
        @contacts_of_contact = @contact.contacts.limit(8)
      else
        @contact ||= Contact.new
      end
    end
  end

  respond_to do |format|
    format.all do
      respond_with @person, :locals => {:post_type => :all}
    end

    format.json { render :json => @stream.stream_posts.map { |p| LastThreeCommentsDecorator.new(PostPresenter.new(p, current_user)) }}
  end
end

#tag_indexObject


69
70
71
72
73
# File 'app/controllers/people_controller.rb', line 69

def tag_index
  profiles = Profile.tagged_with(params[:name]).where(:searchable => true).select('profiles.id, profiles.person_id')
  @people = Person.where(:id => profiles.map{|p| p.person_id}).paginate(:page => params[:page], :per_page => 15)
  respond_with @people
end