Skip to content

DEV: Remove the legacy widget post menu code #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -19,7 +19,16 @@ export default class SolvedAcceptAnswerButton extends Component {

@action
acceptAnswer() {
acceptAnswer(this.args.post, this.appEvents, this.currentUser);
const post = this.args.post;

acceptPost(post, this.currentUser);

this.appEvents.trigger("discourse-solved:solution-toggled", post);

post.get("topic.postStream.posts").forEach((p) => {
p.set("topic_accepted_answer", true);
this.appEvents.trigger("post-stream:refresh", { id: p.id });
});
}

<template>
@@ -34,18 +43,6 @@ export default class SolvedAcceptAnswerButton extends Component {
</template>
}

export function acceptAnswer(post, appEvents, acceptingUser) {
// TODO (glimmer-post-menu): Remove this exported function and move the code into the button action after the widget code is removed
acceptPost(post, acceptingUser);

appEvents.trigger("discourse-solved:solution-toggled", post);

post.get("topic.postStream.posts").forEach((p) => {
p.set("topic_accepted_answer", true);
appEvents.trigger("post-stream:refresh", { id: p.id });
});
}

function acceptPost(post, acceptingUser) {
const topic = post.topic;

Original file line number Diff line number Diff line change
@@ -10,18 +10,6 @@ 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
unacceptPost(post);

appEvents.trigger("discourse-solved:solution-toggled", post);

post.get("topic.postStream.posts").forEach((p) => {
p.set("topic_accepted_answer", false);
appEvents.trigger("post-stream:refresh", { id: p.id });
});
}

function unacceptPost(post) {
if (!post.can_unaccept_answer) {
return;
@@ -48,7 +36,16 @@ export default class SolvedUnacceptAnswerButton extends Component {

@action
unacceptAnswer() {
unacceptAnswer(this.args.post, this.appEvents);
const post = this.args.post;

unacceptPost(post);

this.appEvents.trigger("discourse-solved:solution-toggled", post);

post.get("topic.postStream.posts").forEach((p) => {
p.set("topic_accepted_answer", false);
this.appEvents.trigger("post-stream:refresh", { id: p.id });
});
}

get solvedBy() {
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed } from "@ember/object";
import discourseComputed from "discourse/lib/decorators";
import { withSilencedDeprecations } from "discourse/lib/deprecated";
import { iconHTML, iconNode } from "discourse/lib/icon-library";
import { iconHTML } from "discourse/lib/icon-library";
import { withPluginApi } from "discourse/lib/plugin-api";
import { formatUsername } from "discourse/lib/utilities";
import Topic from "discourse/models/topic";
@@ -72,7 +72,7 @@ function initializeWithApi(api) {
}

function customizePostMenu(api) {
const transformerRegistered = api.registerValueTransformer(
api.registerValueTransformer(
"post-menu-buttons",
({
value: dag,
@@ -109,59 +109,6 @@ function customizePostMenu(api) {
);
}
);

const silencedKey =
transformerRegistered && "discourse.post-menu-widget-overrides";

withSilencedDeprecations(silencedKey, () => customizeWidgetPostMenu(api));
}

function customizeWidgetPostMenu(api) {
const currentUser = api.getCurrentUser();

api.addPostMenuButton("solved", (attrs) => {
if (attrs.can_accept_answer) {
const isOp = currentUser?.id === attrs.topicCreatedById;

return {
action: "acceptAnswer",
icon: "far-square-check",
className: "unaccepted",
title: "solved.accept_answer",
label: isOp ? "solved.solution" : null,
position: attrs.topic_accepted_answer ? "second-last-hidden" : "first",
};
} else if (attrs.accepted_answer) {
if (attrs.can_unaccept_answer) {
return {
action: "unacceptAnswer",
icon: "square-check",
title: "solved.unaccept_answer",
className: "accepted fade-out",
position: "first",
label: "solved.solution",
};
} else {
return {
className: "hidden",
disabled: "true",
position: "first",
beforeButton(h) {
return h(
"span.accepted-text",
{
title: i18n("solved.accepted_description"),
},
[
h("span", iconNode("check")),
h("span.accepted-label", i18n("solved.solution")),
]
);
},
};
}
}
});
}

export default {
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ acceptance(
needs.user({ admin: true });

needs.settings({
glimmer_post_menu_mode: "enabled",
solved_enabled: true,
allow_solved_on_all_topics: true,
});

This file was deleted.