はい、テーマ/コンポーネントのヘッダータブで次のようなものを試すことができます。わかりやすいようにスニペットにコメントを残しておきました。準備ができたら削除できます。
同じルールが適用されます。ユーザーがグループのメンバーであり、グループにメッセージがある場合、Discourse はグループ受信トレイに移動します。それ以外の場合、ユーザーはメンバーディレクトリに移動します。
<script type="text/discourse-plugin" version="0.8">
// Part 1: modify the path for the links in the group cards. This ensure that the link
// title reflects where it leads and handles opening the link a new tab.
const discourseComputed = require("discourse-common/utils/decorators").default;
api.modifyClass("component:group-card-contents", {
// The groupPath property is used to generate the href for the group links
// in the group card. Let's modify it
@discourseComputed("group")
groupPath(group) {
// get the default value from core
let groupURL = this._super(...arguments);
// if the user matches our requirment, modify the url so it goes to the inbox
if (group.is_group_user && group.has_messages) {
groupURL = `${groupURL}/messages/`;
}
// return either the default or modified value
return groupURL;
}
});
// Part 2: modify in-app routing. This ensures that regular in-app navigation is
// handled correctly and takes the user to the group inbox if they meet the
// requirements
const DiscourseURL = require("discourse/lib/url").default;
const { groupPath } = require("discourse/lib/url");
const { action } = require("@ember/object");
api.modifyClass("controller:user-card", {
// showGroup here is an action that belongs to the user-card controller.
// This is what gets called when you click on the group name / avatar inside group cards
@action
showGroup(group) {
// call super to make sure code from core is loaded first
this._super(...arguments);
// group path is a built-in Discourse url helper function
let groupURL = groupPath(group.name);
// if the user matches the requirments, modify the url
if (group.is_group_user && group.has_messages) {
groupURL = `${groupURL}/messages/`;
}
// call routeTo() with either the default or the modified groupURL
DiscourseURL.routeTo(groupURL);
}
});
</script>