diaspora/app/presenters/person_presenter.rb
Denis Hovart bcace2def2 6840 : meta tags update (#6998)
* Adds a new metadata helper and methods to PostPresenter to have metas on post pages.

* Adds tests to post controller to check correctness of metas

* Add methods to PersonPresenter to have metas on profile pages

* Correct meta data helper test

* Update PersonPresenter, add test to PeopleController

* Creates TagPresenter. Display tag metas on tag index page

* Updata meta data helper spec

* Not displaying bio as the description meta on profile page for now. Privacy concerns to be cleared.

* Set meta info as hashes in presenters

* Move original hardcoded metas info to config/defaults.yml

* metas_tags include by default the general metas, update views

* Update code style, clean views

* Renames TagPresenter StreamTagPresenter, updates TagController spec

* Add a default_metas entry to diaspora.yml.example

* Align metas hash in presenters, refactor meta data helper

* Use bio as description meta if user has a public profile

* Rename StreamTagPresenter to TagStreamPresenter
2016-08-18 21:52:39 +02:00

127 lines
3.2 KiB
Ruby

class PersonPresenter < BasePresenter
def base_hash
{
id: id,
guid: guid,
name: name,
diaspora_id: diaspora_handle
}
end
def full_hash
base_hash_with_contact.merge(
relationship: relationship,
block: is_blocked? ? BlockPresenter.new(current_user_person_block).base_hash : false,
is_own_profile: own_profile?,
show_profile_info: public_details? || own_profile? || person_is_following_current_user
)
end
def as_json(_options={})
full_hash_with_profile
end
def hovercard
base_hash_with_contact.merge(profile: ProfilePresenter.new(profile).for_hovercard)
end
def metas_attributes
{
keywords: {name: "keywords", content: comma_separated_tags},
description: {name: "description", content: description},
og_title: {property: "og:title", content: title},
og_description: {property: "og:title", content: description},
og_url: {property: "og:url", content: url},
og_image: {property: "og:image", content: image_url},
og_type: {property: "og:type", content: "profile"},
og_profile_username: {property: "og:profile:username", content: name},
og_profile_firstname: {property: "og:profile:first_name", content: first_name},
og_profile_lastname: {property: "og:profile:last_name", content: last_name}
}
end
protected
def own_profile?
current_user.try(:person) == @presentable
end
def relationship
return false unless current_user
return :blocked if is_blocked?
contact = current_user_person_contact
return :not_sharing unless contact
%i(mutual sharing receiving).find do |status|
contact.public_send("#{status}?")
end || :not_sharing
end
def person_is_following_current_user
return false unless current_user
contact = current_user_person_contact
contact && contact.sharing?
end
def base_hash_with_contact
base_hash.merge(
contact: (!own_profile? && has_contact?) ? contact_hash : false
)
end
def full_hash_with_profile
attrs = full_hash
if attrs[:show_profile_info]
attrs.merge!(profile: ProfilePresenter.new(profile).private_hash)
else
attrs.merge!(profile: ProfilePresenter.new(profile).public_hash)
end
attrs
end
def contact_hash
ContactPresenter.new(current_user_person_contact).full_hash
end
private
def current_user_person_block
@block ||= (current_user ? current_user.block_for(@presentable) : Block.none)
end
def current_user_person_contact
@contact ||= (current_user ? current_user.contact_for(@presentable) : Contact.none)
end
def has_contact?
current_user_person_contact.present?
end
def is_blocked?
current_user_person_block.present?
end
def title
name
end
def comma_separated_tags
profile.tags.map(&:name).join(", ") if profile.tags
end
def url
url_for(@presentable)
end
def description
public_details? ? bio : ""
end
def image_url
return AppConfig.url_to @presentable.image_url if @presentable.image_url[0] == "/"
@presentable.image_url
end
end