Module: MuckFriendsHelper

Defined in:
app/helpers/muck_friends_helper.rb

Instance Method Summary collapse

Instance Method Details



139
140
141
142
# File 'app/helpers/muck_friends_helper.rb', line 139

def accept_follower_link(user, target)
  dom_id = make_id(user, target)
  wrap_friend_link(link_to( I18n.t('muck.friends.accept'), user_friends_path(user, target), :id => "accept-#{target.id}", :class => 'notification-link ajax-update'), dom_id)
end

#all_friends(user) ⇒ Object



3
4
5
# File 'app/helpers/muck_friends_helper.rb', line 3

def all_friends(user)
  render :partial => 'friends/all_friends', :locals => { :user => user }
end


77
78
79
80
81
82
83
84
85
86
87
# File 'app/helpers/muck_friends_helper.rb', line 77

def block_user_link(user, target)
  return '' if user.blank?
  friend = user.friendship_with(target)
  return '' if friend.blank?
  dom_id = make_block_id(user, target)
  if friend.blocked?
    return wrap_friend_link(link_to( I18n.t('muck.friends.unblock', :user => target.display_name), user_friend_path(user, friend, :target_id => target, :unblock => true), :class => 'ajax-update'), dom_id, 'friendship-block')
  else
    return wrap_friend_link(link_to( I18n.t('muck.friends.block', :user => target.display_name), user_friend_path(user, friend, :target_id => target, :block => true), :class => 'ajax-update'), dom_id, 'friendship-block')
  end
end

#followers(user, limit = 6, no_friends_content = nil, partial = 'friend_simple') ⇒ Object

Renders a partial that contains the friends of the given user Parameters: user: User whose friends are to be shown limit: Number of records to show partial: The partial to render. Default is ‘friend_simple’ which renders an icon and name for each friend.

Options include 'friend_icon' which only renders an icon or a custom partial.  Place custom partials
in app/views/friends

no_friends_content: Content to render if no users are found. Pass ‘ ’ to render nothing



47
48
49
50
51
52
# File 'app/helpers/muck_friends_helper.rb', line 47

def followers(user, limit = 6, no_friends_content = nil, partial = 'friend_simple')
  return '' if user.blank?
  users = user.followers.find(:all, :limit => limit, :order => 'friends.created_at DESC')
  no_friends_content ||= t('muck.friends.no_followers')
  render_friends(users, partial, no_friends_content)
end

#followings(user, limit = 6, no_friends_content = nil, partial = 'friend_simple') ⇒ Object

Renders a partial that contains the friends of the given user Parameters: user: User whose friends are to be shown limit: Number of records to show partial: The partial to render. Default is ‘friend_simple’ which renders an icon and name for each friend.

Options include 'friend_icon' which only renders an icon or a custom partial.  Place custom partials
in app/views/friends

no_friends_content: Content to render if no users are found. Pass ‘ ’ to render nothing



62
63
64
65
66
67
# File 'app/helpers/muck_friends_helper.rb', line 62

def followings(user, limit = 6, no_friends_content = nil, partial = 'friend_simple')
  return '' if user.nil?
  users = user.followings.find(:all, :limit => limit, :order => 'friends.created_at DESC')
  no_friends_content ||= t('muck.friends.not_following_anyone')
  render_friends(users, partial, no_friends_content)
end

Render a follow/unfollow/friend request link appropriate to the current application settings and user relationship Requires enable_following and enable_friending be set in configuration see README

If enable_following is true and enable_friending is false then only follow/unfollow links will be shown
If enable_following is false and enable_friending is true then only friend request and unfriend links will be shown
If enable_following is true and enable_friending is true then a hybrid model will be used.  Users can follow
each other without permission but a mutual follow will result in a friendship.  Defriending a user will result in the
other user becoming a follower


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/helpers/muck_friends_helper.rb', line 96

def friend_link(user, target)
  
  # User not logged in
  if user.blank?
    if MuckFriends.configuration.enable_following
      key = 'login_or_sign_up_to_follow'
    elsif MuckFriends.configuration.enable_friending
      key = 'login_or_sign_up_to_friend'
    else
      return ''
    end
    return wrap_friend_link(I18n.t("muck.friends.#{key}", :login => link_to(t('muck.friends.login'), ), :signup => link_to(t('muck.friends.signup'), )))
  end
  
  return '' if target.blank?
  return '' if user == target
  
  dom_id = make_id(user, target)
      
  if MuckFriends.configuration.enable_friending
    if user.friend_of?(target)
      return wrap_friend_link(link_to( I18n.t('muck.friends.stop_being_friends_with', :user => target.display_name), user_friend_path(user, target), :class => 'ajax-delete'), dom_id)
    elsif user.following?(target)
      return wrap_friend_link( I18n.t('muck.friends.friend_request_pending', :link => link_to(I18n.t('muck.friends.delete'), user_friend_path(user, target), :class => 'ajax-delete')), dom_id)
    end
  elsif MuckFriends.configuration.enable_following
    if user.following?(target)
      return wrap_friend_link(link_to( I18n.t('muck.friends.stop_following', :user => target.display_name), user_friend_path(user, target), :class => 'ajax-delete'), dom_id)
    end
  end
  
  if MuckFriends.configuration.enable_friending && user.followed_by?(target)
    return wrap_friend_link(link_to( I18n.t('muck.friends.acccept_friend_request', :user => target.display_name), user_friends_path(user, :id => target), :class => 'ajax-update'), dom_id)
  end
  
  if MuckFriends.configuration.enable_following
    wrap_friend_link(link_to( I18n.t('muck.friends.start_following', :user => target.display_name), user_friends_path(user, :id => target), :class => 'ajax-update'), dom_id)
  elsif MuckFriends.configuration.enable_friending
    wrap_friend_link(link_to( I18n.t('muck.friends.friend_request_prompt', :user => target.display_name), user_friends_path(user, :id => target), :class => 'ajax-update'), dom_id)
  end
  
end

#friend_requests(user) ⇒ Object

Render a list of all friend requests (if !MuckFriends.configuration.enable_following)



70
71
72
73
74
75
# File 'app/helpers/muck_friends_helper.rb', line 70

def friend_requests(user)
  if !MuckFriends.configuration.enable_following 
    followers = user.followers
    render :partial => 'friends/friend_requests', :locals =>  { :followers => followers } unless followers.blank?
  end
end

#friends(user, limit = 6, no_friends_content = nil, partial = 'friend_simple') ⇒ Object

Renders a partial that contains the friends of the given user Parameters: user: User whose friends are to be shown limit: Number of records to show partial: The partial to render. Default is ‘friend_simple’ which renders an icon and name for each friend.

Options include 'friend_icon' which only renders an icon or a custom partial.  Place custom partials
in app/views/friends

no_friends_content: Content to render if no users are found. Pass ‘ ’ to render nothing



32
33
34
35
36
37
# File 'app/helpers/muck_friends_helper.rb', line 32

def friends(user, limit = 6, no_friends_content = nil, partial = 'friend_simple')
  return '' if user.blank?
  users = user.friends.find(:all, :limit => limit, :order => 'friends.created_at DESC')
  no_friends_content ||= t('muck.friends.no_friends')
  render_friends(users, partial, no_friends_content)
end


144
145
146
147
# File 'app/helpers/muck_friends_helper.rb', line 144

def ignore_friend_request_link(user, target)
  dom_id = make_id(user, target)
  wrap_friend_link(link_to( I18n.t('muck.friends.ignore'), user_friend_path(user, target), :id => "ignore-#{target.id}", :class => 'notification-link ajax-delete'), dom_id)
end

#mutual_friends(user1, user2, limit = 6, no_friends_content = nil, partial = 'friend_simple') ⇒ Object

Renders a partial that contains the friends of the given user Parameters: user1: User whose friends are to be shown user2: User whose friends are to be checked to see if they are in common with user1 limit: Number of records to show partial: The partial to render. Default is ‘friend_simple’ which renders an icon and name for each friend.

Options include 'friend_icon' which only renders an icon or a custom partial.  Place custom partials
in app/views/friends

no_friends_content: Content to render if no users are found. Pass ‘ ’ to render nothing



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

def mutual_friends(user1, user2, limit = 6, no_friends_content = nil, partial = 'friend_simple')
  return '' if user1.blank? || user2.blank?
  users = user1.friends & user2.friends
  users = users.first(limit)
  no_friends_content ||= t('muck.friends.no_mutual_friends')
  render_friends(users, partial, no_friends_content)
end