From d1ad34eb9cd0f178dcbc325ca72b54834a104ee2 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 21 Jun 2022 14:52:23 +0200 Subject: [PATCH] Apply anon display name settings to question author display --- app/helpers/application_helper/title_methods.rb | 3 ++- app/helpers/social_helper/tumblr_methods.rb | 8 ++++---- app/helpers/user_helper.rb | 11 +++++++---- app/views/answerbox/_header.haml | 2 +- app/views/inbox/_entry.haml | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/helpers/application_helper/title_methods.rb b/app/helpers/application_helper/title_methods.rb index abbdd040..163d583c 100644 --- a/app/helpers/application_helper/title_methods.rb +++ b/app/helpers/application_helper/title_methods.rb @@ -26,7 +26,8 @@ module ApplicationHelper::TitleMethods end def question_title(question) - name = user_screen_name question.user, anonymous: question.author_is_anonymous, url: false + context_user = question.answers&.first&.user if question.direct + name = user_screen_name question.user, context_user: context_user, anonymous: question.author_is_anonymous, url: false generate_title name, "asked", question.content end diff --git a/app/helpers/social_helper/tumblr_methods.rb b/app/helpers/social_helper/tumblr_methods.rb index f6e4710c..64987346 100644 --- a/app/helpers/social_helper/tumblr_methods.rb +++ b/app/helpers/social_helper/tumblr_methods.rb @@ -3,10 +3,10 @@ require 'cgi' module SocialHelper::TumblrMethods def tumblr_title(answer) asker = if answer.question.author_is_anonymous? - APP_CONFIG['anonymous_name'] - else - answer.question.user.profile.safe_name - end + answer.user.profile.anon_display_name.presence || APP_CONFIG['anonymous_name'] + else + answer.question.user.profile.safe_name + end "#{asker} asked: #{answer.question.content}" end diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb index ab35c452..4a6b4cf7 100644 --- a/app/helpers/user_helper.rb +++ b/app/helpers/user_helper.rb @@ -1,13 +1,16 @@ module UserHelper # Decides what user name to show. + # @param context_user [User] the user whose the profile preferences should be applied # @return [String] The user name - def user_screen_name(user, anonymous: false, url: true, link_only: false) - return APP_CONFIG['anonymous_name'] if user.nil? || anonymous - name = user.profile.display_name.blank? ? user.screen_name : user.profile.display_name + def user_screen_name(user, context_user: nil, anonymous: false, url: true, link_only: false) + return context_user&.profile&.anon_display_name.presence || APP_CONFIG['anonymous_name'] 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?}") + + return link_to(name, link, class: ("user--banned" if user.banned?).to_s) end name.strip end diff --git a/app/views/answerbox/_header.haml b/app/views/answerbox/_header.haml index 33f975dc..c9d05d1c 100644 --- a/app/views/answerbox/_header.haml +++ b/app/views/answerbox/_header.haml @@ -23,7 +23,7 @@ %i.fa.fa-gears View in Kontrollzentrum %h6.text-muted.media-heading.answerbox__question-user - = raw t('views.answerbox.asked', user: user_screen_name(a.question.user, anonymous: a.question.author_is_anonymous), time: time_tooltip(a.question)) + = raw t('views.answerbox.asked', user: user_screen_name(a.question.user, context_user: a.user, anonymous: a.question.author_is_anonymous), time: time_tooltip(a.question)) - if !a.question.author_is_anonymous && !a.question.direct · %a{ href: show_user_question_path(a.question.user.screen_name, a.question.id) } diff --git a/app/views/inbox/_entry.haml b/app/views/inbox/_entry.haml index ff42217b..5aa0c64c 100644 --- a/app/views/inbox/_entry.haml +++ b/app/views/inbox/_entry.haml @@ -6,7 +6,7 @@ %img.answerbox__question-user-avatar.avatar-md{ src: i.question.user.profile_picture.url(:medium) } .media-body %h6.text-muted.media-heading.answerbox__question-user - = t(".asked_html", user: user_screen_name(i.question.user, anonymous: i.question.author_is_anonymous), time: time_tooltip(i.question)) + = t(".asked_html", user: user_screen_name(i.question.user, context_user: i.user, anonymous: i.question.author_is_anonymous), time: time_tooltip(i.question)) - if !i.question.author_is_anonymous && i.question.answer_count.positive? · %a{ href: show_user_question_path(i.question.user.screen_name, i.question.id) }