Module: MuckFriends::Models::MuckFriend

Extended by:
ActiveSupport::Concern
Defined in:
lib/muck-friends/models/friend.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_follow_activityObject

Add activity that indicates user is following another user



136
137
138
139
140
# File 'lib/muck-friends/models/friend.rb', line 136

def add_follow_activity
  return unless MuckFriends.configuration.enable_friend_activity
  content = I18n.t('muck.friends.follow_activity', :inviter => self.inviter.full_name, :invited => self.invited.full_name)
  add_activity(self.inviter.feed_to, self.inviter, self, 'follow', '', content)
end

#add_friends_with_activityObject

Add an activity that indicates the users have become friends



143
144
145
146
147
# File 'lib/muck-friends/models/friend.rb', line 143

def add_friends_with_activity
  return unless MuckFriends.configuration.enable_friend_activity
  content = I18n.t('muck.friends.friends_with', :inviter => self.inviter.full_name, :invited => self.invited.full_name)
  add_activity(self.inviter.feed_to + self.invited.feed_to, self.inviter, self, 'friends_with', '', content)
end

#after_createObject



116
117
118
# File 'lib/muck-friends/models/friend.rb', line 116

def after_create
  FriendMailer.follow(inviter, invited).deliver
end

#blockObject



120
121
122
# File 'lib/muck-friends/models/friend.rb', line 120

def block
  self.update_attribute(:status, MuckFriends::BLOCKED)
end

#blocked?Boolean

Returns:

  • (Boolean)


128
129
130
131
132
133
# File 'lib/muck-friends/models/friend.rb', line 128

def blocked?
  # TODO status is a reserved word in mysql.  self.status won't work here (just returns nil).
  # Consider setting up 'friend' to use a state machine instead of numeric values
  # doing so would cleanup transitions between states.
  self[:status] == MuckFriends::BLOCKED
end

#check_invitedObject



149
150
151
# File 'lib/muck-friends/models/friend.rb', line 149

def check_invited
  errors.add('inviter', I18n.t('muck.friends.same_inviter_error_message')) if invited == inviter
end

#unblockObject



124
125
126
# File 'lib/muck-friends/models/friend.rb', line 124

def unblock
  self.update_attribute(:status, MuckFriends::FOLLOWING)
end