From d3c0b6bfe13ef41a5919ad8fb0a81bf4f4749ac8 Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Tue, 27 Apr 2021 23:09:32 +0400 Subject: [PATCH] =?UTF-8?q?FEATURE:=20include=20avatar=20flair=20on=20the?= =?UTF-8?q?=20avatars=20listed=20in=20a=20user=20summary=E2=80=99s=20?= =?UTF-8?q?=E2=80=9CMost=E2=80=A6=E2=80=9D=20sections=20(#12858)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user_summary.rb | 10 +++++--- app/serializers/user_summary_serializer.rb | 29 +++++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/app/models/user_summary.rb b/app/models/user_summary.rb index 69796d9fc1a..9edda802f38 100644 --- a/app/models/user_summary.rb +++ b/app/models/user_summary.rb @@ -196,9 +196,13 @@ protected user_ids.map do |user_id| lookup_hash = lookup[user_id] - UserWithCount.new( - lookup_hash.attributes.merge(count: user_hash[user_id]) - ) if lookup_hash.present? + if lookup_hash.present? + primary_group = lookup.primary_groups[user_id] + + UserWithCount.new( + lookup_hash.attributes.merge(count: user_hash[user_id], primary_group: primary_group) + ) + end end.compact.sort_by { |u| -u[:count] } end diff --git a/app/serializers/user_summary_serializer.rb b/app/serializers/user_summary_serializer.rb index 65d0250de13..6776fb50ebe 100644 --- a/app/serializers/user_summary_serializer.rb +++ b/app/serializers/user_summary_serializer.rb @@ -21,7 +21,18 @@ class UserSummarySerializer < ApplicationSerializer end class UserWithCountSerializer < ApplicationSerializer - attributes :id, :username, :name, :count, :avatar_template + attributes :id, + :username, + :name, + :count, + :avatar_template, + :admin, + :moderator, + :trust_level, + :primary_group_flair_url, + :primary_group_flair_bg_color, + :primary_group_flair_color, + :primary_group_name def include_name? SiteSetting.enable_names? @@ -30,6 +41,22 @@ class UserSummarySerializer < ApplicationSerializer def avatar_template User.avatar_template(object[:username], object[:uploaded_avatar_id]) end + + def primary_group_flair_url + object.primary_group&.flair_icon + end + + def primary_group_flair_bg_color + object.primary_group&.flair_bg_color + end + + def primary_group_flair_color + object.primary_group&.flair_color + end + + def primary_group_name + object.primary_group&.name + end end class CategoryWithCountsSerializer < ApplicationSerializer