Sha256: 0b031feff2427cfc7784027271a91eb73d3843052a7a58a6d04b1d9fffe7132d

Contents?: true

Size: 1.19 KB

Versions: 25

Compression:

Stored size: 1.19 KB

Contents

module ActivitiesHelper
  # Link to 'like' or 'unlike' depending if current_subject already unlikes or likes
  # the object respectively
  #
  # @param [Object]
  # @return [String]
  def like_status object
    [ 'like', 'unlike' ].tap do |s|
      if user_signed_in? && object.liked_by?(current_subject)
        s.reverse!
      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, options = {})
    options[:likers_shown] ||= 2

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

    likers_count = activity.likes.count
    likers_other = likers_count - options[:likers_shown]

    if likers_other > 0
      likers.push t("activity_action.sentence.more", :count => likers_other)
    end

    t("activity.like_sentence", :likers => likers.to_sentence, :count => likers_count).html_safe
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
social_stream-2.2.2 base/app/helpers/activities_helper.rb
social_stream-base-2.2.2 app/helpers/activities_helper.rb
social_stream-2.2.1 base/app/helpers/activities_helper.rb
social_stream-base-2.2.1 app/helpers/activities_helper.rb
social_stream-2.2.0 base/app/helpers/activities_helper.rb
social_stream-base-2.2.0 app/helpers/activities_helper.rb
social_stream-2.1.1 base/app/helpers/activities_helper.rb
social_stream-2.1.0 base/app/helpers/activities_helper.rb
social_stream-base-2.1.0 app/helpers/activities_helper.rb
social_stream-2.0.4 base/app/helpers/activities_helper.rb
social_stream-base-2.0.4 app/helpers/activities_helper.rb
social_stream-2.0.3 base/app/helpers/activities_helper.rb
social_stream-base-2.0.3 app/helpers/activities_helper.rb
social_stream-2.0.2 base/app/helpers/activities_helper.rb
social_stream-base-2.0.2 app/helpers/activities_helper.rb
social_stream-2.0.1 base/app/helpers/activities_helper.rb
social_stream-base-2.0.1 app/helpers/activities_helper.rb
social_stream-2.0.0 base/app/helpers/activities_helper.rb
social_stream-base-2.0.0 app/helpers/activities_helper.rb
social_stream-2.0.0.beta3 base/app/helpers/activities_helper.rb