Retrospring/app/helpers/user_helper.rb

24 lines
773 B
Ruby
Raw Normal View History

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