你好,我正在为本地开发使用版本3.2.0.beta4-dev和插件API版本0.8.7进行插件开发。然而,由于Discourse的近期变化,addPostMenuButton和component:topic-list函数已经被修改。
我如何可以为这些API函数使用api.registerValueTransformer?此外,我应该使用哪个插件API版本来匹配3.2.0.beta4-dev,以确保与api.registerValueTransformer的兼容性?
以下是我的addPostMenuButton的代码:
api.addPostMenuButton("togglePostButton", (model) => {
const siteSettings = api.container.lookup("site-settings:main");
const posts = siteSettings.posts;
const array_of_posts = posts.split("|");
const postId = model.id;
const postIdstr = postId.toString();
const isPost = array_of_posts.includes(postIdstr);
return {
action: "togglePost",
position: "first",
className: isPost
? "button.topic_hidden custom-class-hidden"
: "button.topic_visible custom-class-visible",
icon: isPost ? "far-eye-slash" : "far-eye",
title: isPost ? "隐藏帖子" : "显示帖子",
};
});
以及component:topic-list的代码:
api.modifyClass("component:topic-list", {
pluginId: "post-toggle",
didInsertElement: function () {
this._super();
const topics = this.topics;
for (let key in topics) {
if (topics.hasOwnProperty(key)) {
let newTopicLatest = [];
const topic_id = topics[key].id;
const topic_posters = topics[key].posters;
topic_posters.forEach((poster) => {
if (poster && poster.extras !== null && poster.extras.includes("latest")) {
newTopicLatest = poster["description"].split(",");
}
});
let userListLatest = newTopicLatest;
if (userListLatest.length > 1 && userListLatest[0] === "Original Poster") {
userListLatest = userListLatest.slice(1);
userListLatest[0] = userListLatest[0].trim();
}
let i = 0;
const element = $('tr[data-topic-id="' + topic_id + '"]').find(
"a[data-user-card]"
);
if (element.length > 0) {
element.each(function () {
const poster_inside = topic_posters[i];
if (poster_inside !== undefined && Object.keys(poster_inside).length !== 0) {
const userElement = $(this);
if (!userListLatest.includes(poster_inside.user.id.toString())) {
userElement.hide();
}
}
i++;
});
}
}
}
}
});
有人能帮我解决这个问题吗?