mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 04:34:13 -06:00
6c1c8be794
This introduces a new model to store the avatars and 3 uploads per user (gravatar, system and custom) user can then pick which they want.
34 lines
662 B
Ruby
34 lines
662 B
Ruby
class AvatarLookup
|
|
|
|
def initialize(user_ids=[])
|
|
@user_ids = user_ids.tap(&:compact!).tap(&:uniq!).tap(&:flatten!)
|
|
end
|
|
|
|
# Lookup a user by id
|
|
def [](user_id)
|
|
users[user_id]
|
|
end
|
|
|
|
private
|
|
|
|
def self.lookup_columns
|
|
@lookup_columns ||= [:id,
|
|
:email,
|
|
:username,
|
|
:uploaded_avatar_id]
|
|
end
|
|
|
|
def users
|
|
@users ||= user_lookup_hash
|
|
end
|
|
|
|
def user_lookup_hash
|
|
# adding tap here is a personal taste thing
|
|
hash = {}
|
|
User.where(:id => @user_ids)
|
|
.select(AvatarLookup.lookup_columns)
|
|
.each{ |user| hash[user.id] = user }
|
|
hash
|
|
end
|
|
end
|