Class: Muck::FriendsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/muck/friends_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/muck/friends_controller.rb', line 13

def create
  success = Friend.make_friends(@user, @target)

  if MuckFriends.configuration.enable_following
    if success
      message = t('muck.friends.you_are_now_following', :user => @target.display_name)
    else
      message = t('muck.friends.problem_adding_follow', :user => @target.display_name)
    end
  elsif MuckFriends.configuration.enable_friending
    if success
      message = t('muck.friends.friend_request_sent')
    else
      message = t('muck.friends.problem_sending_friend_request', :user  => @target.display_name)
    end
  end

  respond_to do |format|
    format.html { render_after_create_html(success, message) }
    format.js { render_after_create_js(success, message) }
    format.pjs { render_after_create_js(success, message) }
    format.json { render :json => { :success => success, :message => message, :friend_user => @target } }
  end

end

#destroyObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/muck/friends_controller.rb', line 65

def destroy

  success = true
  # Other user may or may not be a friend.  If they weren't then revert_to_follower will return false.
  # We don't care that the other user wasn't reverted to a follower (since they might not have been a friend) so return true
  @user.drop_friend(@target)
  if MuckFriends.configuration.enable_friending 
    message = t('muck.friends.removed_friendship', :user => @target.display_name)
  elsif MuckFriends.configuration.enable_following
    message = t('muck.friends.stopped_following', :user => @target.display_name)
  end

  # if MuckFriends.configuration.enable_friending 
  #   message = t('muck.friends.removed_friendship_error', :user => @target.display_name)
  # elsif MuckFriends.configuration.enable_following
  #   message = t('muck.friends.removed_following_error', :user => @target.display_name)
  # end
  
  respond_to do |format|
    format.html { render_after_destroy_html(success, message) }
    format.js { render_after_destroy_js(success, message) }
    format.pjs { render_after_destroy_js(success, message) }
    format.json { render :json => { :success => success, :message => message } }
  end
end

#indexObject



6
7
8
9
10
11
# File 'app/controllers/muck/friends_controller.rb', line 6

def index
  @user = User.find(params[:user_id]) rescue current_user
  respond_to do |format|
    format.html { render :template => 'friends/index' }
  end
end

#updateObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/muck/friends_controller.rb', line 39

def update
  if params[:block]
    success = @user.block_user(@target)
  elsif params[:unblock]
    success = @user.unblock_user(@target)
  end
  
  if success
    if params[:block]
      message = t('muck.friends.blocked', :user => @target.display_name)
    elsif params[:unblock]
      message = t('muck.friends.unblocked', :user => @target.display_name)
    end
  else
    message = t('muck.friends.block_problem', :user => @target.display_name)
  end
  
  respond_to do |format|
    format.html { render_after_update_html(success, message) }
    format.js { render_after_update_js(success, message) }
    format.pjs { render_after_update_js(success, message) }
    format.json { render :json => { :success => success, :message => message, :friend_user => @target } }
  end
  
end