네, 테마/컴포넌트의 헤더 탭에서 다음과 같은 방식으로 시도해 볼 수 있습니다. 따라 해 보시려면 스니펫에 몇 가지 주석을 남겨 두었습니다. 사용하실 준비가 되면 해당 주석은 삭제해도 됩니다.
같은 규칙이 적용됩니다. 사용자가 해당 그룹의 멤버이고 그룹에 메시지가 있으면 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>