mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Work in progress, keeping avatars locally
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.
This commit is contained in:
@@ -4,6 +4,7 @@ class BasicPostSerializer < ApplicationSerializer
|
||||
:name,
|
||||
:username,
|
||||
:avatar_template,
|
||||
:uploaded_avatar_id,
|
||||
:created_at,
|
||||
:cooked
|
||||
|
||||
@@ -19,6 +20,10 @@ class BasicPostSerializer < ApplicationSerializer
|
||||
object.user.try(:avatar_template)
|
||||
end
|
||||
|
||||
def uploaded_avatar_id
|
||||
object.user.try(:uploaded_avatar_id)
|
||||
end
|
||||
|
||||
def cooked
|
||||
if object.hidden && !scope.is_staff?
|
||||
if scope.current_user && object.user_id == scope.current_user.id
|
||||
|
||||
@@ -1,7 +1,26 @@
|
||||
class BasicUserSerializer < ApplicationSerializer
|
||||
attributes :id, :username, :avatar_template
|
||||
attributes :id, :username, :uploaded_avatar_id, :avatar_template
|
||||
|
||||
def include_name?
|
||||
SiteSetting.enable_names?
|
||||
end
|
||||
|
||||
# so weird we send a hash in here sometimes and an object others
|
||||
def include_uploaded_avatar_id?
|
||||
SiteSetting.allow_uploaded_avatars? &&
|
||||
(Hash === object ? user[:uploaded_avatar_id] : object.uploaded_avatar_id)
|
||||
end
|
||||
|
||||
def avatar_template
|
||||
if Hash === object
|
||||
User.avatar_template(user[:username], user[:uploaded_avatar_id])
|
||||
else
|
||||
object.avatar_template
|
||||
end
|
||||
end
|
||||
|
||||
def user
|
||||
object[:user] || object
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -127,7 +127,8 @@ class PostSerializer < BasicPostSerializer
|
||||
def reply_to_user
|
||||
{
|
||||
username: object.reply_to_user.username,
|
||||
avatar_template: object.reply_to_user.avatar_template
|
||||
avatar_template: object.reply_to_user.avatar_template,
|
||||
uploaded_avatar_id: object.reply_to_user.uploaded_avatar_id
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -10,13 +10,15 @@ class TopicPostCountSerializer < BasicUserSerializer
|
||||
object[:user].username
|
||||
end
|
||||
|
||||
def avatar_template
|
||||
object[:user].avatar_template
|
||||
end
|
||||
|
||||
def post_count
|
||||
object[:post_count]
|
||||
end
|
||||
|
||||
def uploaded_avatar_id
|
||||
object[:user].uploaded_avatar_id
|
||||
end
|
||||
|
||||
def include_uploaded_avatar_id?
|
||||
SiteSetting.allow_uploaded_avatars? && object[:user].use_uploaded_avatar
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,30 +23,20 @@ class UserActionSerializer < ApplicationSerializer
|
||||
:hidden,
|
||||
:moderator_action,
|
||||
:edit_reason,
|
||||
:category_id
|
||||
:category_id,
|
||||
:uploaded_avatar_id,
|
||||
:acting_uploaded_avatar_id
|
||||
|
||||
def excerpt
|
||||
PrettyText.excerpt(object.cooked, 300) if object.cooked
|
||||
end
|
||||
|
||||
def avatar_template
|
||||
avatar_for(
|
||||
object.user_id,
|
||||
object.email,
|
||||
object.use_uploaded_avatar,
|
||||
object.uploaded_avatar_template,
|
||||
object.uploaded_avatar_id
|
||||
)
|
||||
User.avatar_template(object.username, object.uploaded_avatar_id)
|
||||
end
|
||||
|
||||
def acting_avatar_template
|
||||
avatar_for(
|
||||
object.acting_user_id,
|
||||
object.acting_email,
|
||||
object.acting_use_uploaded_avatar,
|
||||
object.acting_uploaded_avatar_template,
|
||||
object.acting_uploaded_avatar_id
|
||||
)
|
||||
User.avatar_template(object.acting_username, object.acting_uploaded_avatar_id)
|
||||
end
|
||||
|
||||
def include_name?
|
||||
|
||||
@@ -63,16 +63,27 @@ class UserSerializer < BasicUserSerializer
|
||||
:external_links_in_new_tab,
|
||||
:dynamic_favicon,
|
||||
:enable_quoting,
|
||||
:use_uploaded_avatar,
|
||||
:has_uploaded_avatar,
|
||||
:gravatar_template,
|
||||
:uploaded_avatar_template,
|
||||
:muted_category_ids,
|
||||
:tracked_category_ids,
|
||||
:watched_category_ids,
|
||||
:private_messages_stats,
|
||||
:disable_jump_reply
|
||||
:disable_jump_reply,
|
||||
:system_avatar_upload_id,
|
||||
:gravatar_avatar_upload_id,
|
||||
:custom_avatar_upload_id,
|
||||
:uploaded_avatar_id
|
||||
|
||||
def system_avatar_upload_id
|
||||
object.user_avatar.try(:system_upload_id)
|
||||
end
|
||||
|
||||
def gravatar_avatar_upload_id
|
||||
object.user_avatar.try(:gravatar_upload_id)
|
||||
end
|
||||
|
||||
def custom_avatar_upload_id
|
||||
object.user_avatar.try(:custom_upload_id)
|
||||
end
|
||||
|
||||
def auto_track_topics_after_msecs
|
||||
object.auto_track_topics_after_msecs || SiteSetting.auto_track_topics_after
|
||||
@@ -106,10 +117,6 @@ class UserSerializer < BasicUserSerializer
|
||||
UserAction.stats(object.id, scope)
|
||||
end
|
||||
|
||||
def gravatar_template
|
||||
User.gravatar_template(object.email)
|
||||
end
|
||||
|
||||
def include_suspended?
|
||||
object.suspended?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user