-
Notifications
You must be signed in to change notification settings - Fork 4k
/
user_decorator.rb
120 lines (106 loc) · 2.62 KB
/
user_decorator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
class UserDecorator < ApplicationDecorator
WHITE_TEXT_COLORS = [
{
bg: "#093656",
text: "#ffffff"
},
{
bg: "#61122f",
text: "#ffffff"
},
{
bg: "#2e0338",
text: "#ffffff"
},
{
bg: "#080E3B",
text: "#ffffff"
},
].freeze
DEFAULT_PROFILE_SUMMARY = "404 bio not found".freeze
def cached_followed_tags
follows_map = Rails.cache.fetch("user-#{id}-#{following_tags_count}-#{last_followed_at&.rfc3339}/followed_tags",
expires_in: 20.hours) do
Follow.follower_tag(id).pluck(:followable_id, :points).to_h
end
tags = Tag.where(id: follows_map.keys).order(hotness_score: :desc)
tags.each do |tag|
tag.points = follows_map[tag.id]
end
tags
end
def darker_color(adjustment = 0.88)
Color::CompareHex.new([enriched_colors[:bg], enriched_colors[:text]]).brightness(adjustment)
end
def enriched_colors
if setting.brand_color1.blank? || setting.brand_color2.blank?
{
bg: assigned_color[:bg],
text: assigned_color[:text]
}
else
{
bg: setting.brand_color1,
text: setting.brand_color2
}
end
end
def config_body_class
body_class = [
setting.config_theme.tr("_", "-"),
"#{setting.resolved_font_name.tr('_', '-')}-article-body",
"trusted-status-#{trusted?}",
"#{setting.config_navbar.tr('_', '-')}-header",
]
body_class.join(" ")
end
def assigned_color
colors = [
{
bg: "#19063A",
text: "#dce9f3"
},
{
bg: "#0D4D4B",
text: "#fdf9f3"
},
{
bg: "#010C1F",
text: "#aebcd5"
},
{
bg: "#d7dee2",
text: "#022235"
},
{
bg: "#161616",
text: "#66e2d5"
},
{
bg: "#1c0bba",
text: "#c9d2dd"
},
]
colors |= WHITE_TEXT_COLORS
colors[(id || rand(100)) % 10]
end
# returns true if the user has been suspended and has no content
def fully_banished?
articles_count.zero? && comments_count.zero? && suspended?
end
def considered_new?
Settings::RateLimit.user_considered_new?(user: self)
end
# Returns the user's public email if it is set and the display_email_on_profile
# settings is set to true.
def profile_email
return unless setting.display_email_on_profile?
email
end
# Returns the users profile summary or a placeholder text
def profile_summary
profile.summary.presence || DEFAULT_PROFILE_SUMMARY
end
delegate :display_sponsors, to: :setting
delegate :display_announcements, to: :setting
end