Module: ActivitiesHelper

Defined in:
app/helpers/activities_helper.rb

Instance Method Summary collapse

Instance Method Details

#like_sentence(activity, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/activities_helper.rb', line 23

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

#like_status(object) ⇒ String

Link to ‘like’ or ‘unlike’ depending if current_subject already unlikes or likes the object respectively

Parameters:

  • (Object)

Returns:

  • (String)


7
8
9
10
11
12
13
# File 'app/helpers/activities_helper.rb', line 7

def like_status object
  [ 'like', 'unlike' ].tap do |s|
    if user_signed_in? && object.liked_by?(current_subject)
      s.reverse!
    end
  end
end

#new_post(receiver) ⇒ Object

Build a new post based on the current_subject. Useful for authorization queries



16
17
18
19
20
21
# File 'app/helpers/activities_helper.rb', line 16

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