DiscourseプラグインAPIの変更: addPostMenuButtonとcomponent:topic-listに対してapi.registerValueTransformerを使用する

{“content”: “こんにちは、私はローカル開発用にバージョン3.2.0.beta4-devを使用しており、プラグインAPIのバージョンは0.8.7です。ただし、最近のDiscourseの変更により、addPostMenuButtoncomponent:topic-list関数が変更されました。\n\nこれらのAPI関数に対してapi.registerValueTransformerをどのように使用すればよいですか?また、api.registerValueTransformerに互換性のあるバージョンのプラグインAPIを使用するには、どのバージョンを選べばよいですか?\n\nこちらはaddPostMenuButtonのコードです:\n\napi.addPostMenuButton("togglePostButton", (model) => {\n const siteSettings = api.container.lookup("site-settings:main");\n const posts = siteSettings.posts;\n const array_of_posts = posts.split("|");\n const postId = model.id;\n const postIdstr = postId.toString();\n const isPost = array_of_posts.includes(postIdstr);\n\n return {\n action: "togglePost",\n position: "first",\n className: isPost\n ? "button.topic_hidden custom-class-hidden"\n : "button.topic_visible custom-class-visible",\n icon: isPost ? "far-eye-slash" : "far-eye",\n title: isPost ? "Hide Post" : "Show Post",\n };\n});\n\nこちらはcomponent:topic-listのコードです:\n\napi.modifyClass("component:topic-list", {\n pluginId: "post-toggle",\n didInsertElement: function () {\n this._super();\n const topics = this.topics;\n for (let key in topics) {\n if (topics.hasOwnProperty(key)) {\n let newTopicLatest = [];\n const topic_id = topics[key].id;\n const topic_posters = topics[key].posters;\n\n topic_posters.forEach((poster) => {\n if (poster && poster.extras !== null && poster.extras.includes("latest")) {\n newTopicLatest = poster["description"].split(",");\n }\n });\n\n let userListLatest = newTopicLatest;\n if (userListLatest.length > 1 && userListLatest[0] === "Original Poster") {\n userListLatest = userListLatest.slice(1);\n userListLatest[0] = userListLatest[0].trim();\n }\n\n let i = 0;\n const element = $('tr[data-topic-id="' + topic_id + '"]').find(\n "a[data-user-card]"\n );\n\n if (element.length > 0) {\n element.each(function () {\n const poster_inside = topic_posters[i];\n if (poster_inside !== undefined && Object.keys(poster_inside).length !== 0) {\n const userElement = $(this);\n if (!userListLatest.includes(poster_inside.user.id.toString())) {\n userElement.hide();\n }\n }\n i++;\n });\n }\n }\n }\n }\n});\n\n誰か助けてくれますか?”}

ローカル開発のDiscourseをバージョン3.5.0.beta2-devにアップデートしました。プラグインAPIのバージョンは2.1.1です。addPostMenuButtonおよびcomponent:topic-list関数でapi.registerValueTransformerを使用するにはどうすればよいですか?

トピックを読みましたか? Upcoming post menu changes - How to prepare themes and plugins

「いいね!」 3

はい、そのトピックについて読みました。新しいプラグインAPIのアップデートに基づいて変更を実装し、component:topic-listについても理解しました。

「いいね!」 1

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.