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.
This commit is contained in:
Natalie Tay
2025-03-26 11:43:22 +08:00
committed by GitHub
parent 6b07af89da
commit a8a3554cec
8 changed files with 73 additions and 10 deletions
@@ -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,
});
}
}
<template>
<span class="extra-buttons">
{{#if @post.can_unaccept_answer}}
<DButton
class="post-action-menu__solved-accepted accepted fade-out"
...attributes
@action={{this.unacceptAnswer}}
@icon="square-check"
@label="solved.solution"
@title="solved.unaccept_answer"
/>
{{#if this.solvedBy}}
<DTooltip @identifier="post-action-menu__solved-accepted-tooltip">
<:trigger>
<DButton
class="post-action-menu__solved-accepted accepted fade-out"
...attributes
@action={{this.unacceptAnswer}}
@icon="square-check"
@label="solved.solution"
@title="solved.unaccept_answer"
/>
</:trigger>
<:content>
{{htmlSafe this.solvedBy}}
</:content>
</DTooltip>
{{else}}
<DButton
class="post-action-menu__solved-accepted accepted fade-out"
...attributes
@action={{this.unacceptAnswer}}
@icon="square-check"
@label="solved.solution"
@title="solved.unaccept_answer"
/>
{{/if}}
{{else}}
<span
class="accepted-text"
@@ -195,6 +195,9 @@ export default {
accepterHtml: computed("accepted_answer", function () {
const username = this.get("accepted_answer.accepter_username");
const name = this.get("accepted_answer.accepter_name");
if (!this.siteSettings.show_who_marked_solved) {
return "";
}
const formattedUsername =
this.siteSettings.display_name_on_posts && name
? name