Sha256: 121534bff855b21a4a3dc206d43abe8a80bcfda8e86ac393800b7b4517bb68e0

Contents?: true

Size: 1.91 KB

Versions: 10

Compression:

Stored size: 1.91 KB

Contents

module ActivitiesHelper
  # Link to 'like' or 'unlike' depending on the like status of the activity to current_subject
  #
  # @param [Object]
  # @return [String]
  def link_like(object)
    params = link_like_params(object)
    link_to params[0],params[1],params[2]
  end

  def link_like_params(object)
    params = Array.new
    if !user_signed_in?
      params << image_tag("btn/nolike.png", :class => "menu_icon")+t('activity.like')
      params << new_user_session_path
      params << {:class => "verb_like",:id => "like_" + dom_id(object)}
    else
      if (object.liked_by?(current_subject))
        params << image_tag("btn/like.png", :class => "menu_icon")+t('activity.unlike')
        params << [object, :like]
        params << {:class => "verb_like",:id => "like_" + dom_id(object),:method => :delete, :remote => true}
      else
        params << image_tag("btn/nolike.png", :class => "menu_icon")+t('activity.like')
        params << [object, :like]
        params << {:class => "verb_like",:id => "like_" + dom_id(object),:method => :post, :remote => true}
      end
    end
  end

  # Build a new post based on the current_subject. Useful for authorization queries
  def new_post(receiver)
    return Post.new unless user_signed_in?

    Post.new :author_id => Actor.normalize_id(current_subject),
             :owner_id  => Actor.normalize_id(receiver)
  end

  def like_sentence(activity)
    likers_shown = 3
    likers_count = activity.likes.count
    likers_other = likers_count - likers_shown

    # TODO: select likers from current_subject's contacts
    likers =
      activity.likes.first(likers_shown).
      map{ |a| a.sender_subject }.
      map{ |l| link_to l.name, l }.
      join(", ")

    if likers_other > 0
      t("activity.like_sentence.many", :likers => likers, :count => likers_other).html_safe
    else
      t("activity.like_sentence.few",  :likers => likers, :count => likers_count).html_safe
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
social_stream-0.23.4 base/app/helpers/activities_helper.rb
social_stream-base-0.17.3 app/helpers/activities_helper.rb
social_stream-0.23.3 base/app/helpers/activities_helper.rb
social_stream-base-0.17.2 app/helpers/activities_helper.rb
social_stream-0.23.2 base/app/helpers/activities_helper.rb
social_stream-base-0.17.1 app/helpers/activities_helper.rb
social_stream-0.23.1 base/app/helpers/activities_helper.rb
social_stream-base-0.17.0 app/helpers/activities_helper.rb
social_stream-0.22.1 base/app/helpers/activities_helper.rb
social_stream-base-0.16.4 app/helpers/activities_helper.rb