From a8a3554cec5ad222a596f7c453d06e4065837f4e Mon Sep 17 00:00:00 2001 From: Natalie Tay Date: Wed, 26 Mar 2025 11:43:22 +0800 Subject: [PATCH] FEATURE: Add setting to show who marked as solved (#347) This commit adds the site setting `SiteSetting.show_who_marked_solved` and also the following tooltip to answer posts. --- .../solved-unaccept-answer-button.gjs | 57 ++++++++++++++++--- .../initializers/extend-for-solved-button.js | 3 + assets/stylesheets/solutions.scss | 5 ++ config/locales/server.en.yml | 1 + config/settings.yml | 3 + .../topic_view_serializer_extension.rb | 7 ++- spec/requests/topics_controller_spec.rb | 6 ++ spec/system/solved_spec.rb | 1 + 8 files changed, 73 insertions(+), 10 deletions(-) diff --git a/assets/javascripts/discourse/components/solved-unaccept-answer-button.gjs b/assets/javascripts/discourse/components/solved-unaccept-answer-button.gjs index 2c0b862..5f125d5 100644 --- a/assets/javascripts/discourse/components/solved-unaccept-answer-button.gjs +++ b/assets/javascripts/discourse/components/solved-unaccept-answer-button.gjs @@ -1,11 +1,14 @@ import Component from "@glimmer/component"; import { action } from "@ember/object"; import { service } from "@ember/service"; +import { htmlSafe } from "@ember/template"; import DButton from "discourse/components/d-button"; import icon from "discourse/helpers/d-icon"; import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; +import { formatUsername } from "discourse/lib/utilities"; import { i18n } from "discourse-i18n"; +import DTooltip from "float-kit/components/d-tooltip"; export function unacceptAnswer(post, appEvents) { // TODO (glimmer-post-menu): Remove this exported function and move the code into the button action after the widget code is removed @@ -41,23 +44,61 @@ function unacceptPost(post) { export default class SolvedUnacceptAnswerButton extends Component { @service appEvents; + @service siteSettings; @action unacceptAnswer() { unacceptAnswer(this.args.post, this.appEvents); } + get solvedBy() { + if (!this.siteSettings.show_who_marked_solved) { + return; + } + + const username = this.args.post.topic.accepted_answer.accepter_username; + const name = this.args.post.topic.accepted_answer.accepter_name; + const displayedName = + this.siteSettings.display_name_on_posts && name + ? name + : formatUsername(username); + if (this.args.post.topic.accepted_answer.accepter_username) { + return i18n("solved.marked_solved_by", { + username: displayedName, + username_lower: username, + }); + } + } +