2014-11-02 17:57:37 +01:00
|
|
|
module UserHelper
|
2014-11-11 07:09:36 +01:00
|
|
|
# Decides what user name to show.
|
2022-06-21 14:52:23 +02:00
|
|
|
# @param context_user [User] the user whose the profile preferences should be applied
|
2014-11-11 07:09:36 +01:00
|
|
|
# @return [String] The user name
|
2022-06-21 14:52:23 +02:00
|
|
|
def user_screen_name(user, context_user: nil, anonymous: false, url: true, link_only: false)
|
2022-06-21 16:27:07 +02:00
|
|
|
return anonymous_name(context_user) if user.nil? || anonymous
|
2022-06-21 14:52:23 +02:00
|
|
|
|
|
|
|
name = user.profile.display_name.presence || user.screen_name
|
2017-03-30 19:17:25 +02:00
|
|
|
if url
|
|
|
|
link = show_user_profile_path(user.screen_name)
|
|
|
|
return link if link_only
|
2022-06-21 14:52:23 +02:00
|
|
|
|
|
|
|
return link_to(name, link, class: ("user--banned" if user.banned?).to_s)
|
2017-03-30 19:17:25 +02:00
|
|
|
end
|
2015-06-09 18:05:35 +02:00
|
|
|
name.strip
|
2014-11-11 07:09:36 +01:00
|
|
|
end
|
2022-06-21 16:27:07 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def anonymous_name(context_user)
|
2022-06-25 10:33:48 +02:00
|
|
|
sanitize(context_user&.profile&.anon_display_name.presence || APP_CONFIG["anonymous_name"])
|
2022-06-21 16:27:07 +02:00
|
|
|
end
|
2014-11-02 17:57:37 +01:00
|
|
|
end
|