将默认群组页面更改为/messages

当然,您可以在主题/组件的 header 标签中尝试类似以下的代码。我留下了一些注释,如果您想跟随。准备好使用时可以删除它们。

同样的应用规则。如果用户是组成员并且该组有消息,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>