Sha256: 7b7e9e8c5198d7c18f36c8fa763283ca4f812535ea11839e48f2bc5851676dd8
Contents?: true
Size: 852 Bytes
Versions: 8
Compression:
Stored size: 852 Bytes
Contents
module Likeable module Facepile # returns friend of user who like target def liked_friends(user, limit = nil) friend_ids = liked_friend_ids(user) friend_ids = friend_ids.sample(limit) unless limit.blank? @liked_friends ||= Likeable.find_many(User, friend_ids) end def liked_friend_ids(user) @liked_friend_ids ||= like_user_ids & user.friend_ids end def ids_for_facepile(user, limit = Likeable.facepile_default_limit) ids = liked_friend_ids(user).shuffle + like_user_ids.shuffle # show friends first ids.uniq.first(limit) end def users_for_facepile(user, limit = Likeable.facepile_default_limit) return [] if user.blank? @facepile ||= begin return nil unless ids = ids_for_facepile(user, limit) Likeable.find_many(User, ids) end end end end
Version data entries
8 entries across 8 versions & 1 rubygems