Reply reminder - Remind users to reply to new users topics with zero replies

我们一直使用这个主题组件有一段时间了,但今天它出问题了。

以下是组件代码(common/head_tag.html):

<!-- NEEDS REPLY -->
<script type="text/discourse-plugin" version="0.8.18">
    if (I18n.translations.en) {
        I18n.translations.en.js.filters.needsreply = {title: "Needs Reply", help: "Unanswered Topics"};
    }

    // CUSTOMIZE THESE VALUES
    // 设置搜索查询
    let search_query = '?ascending=false&max_posts=1';
    // 从“需要回复”菜单项中排除某些分类
    let excludeList = ['pitches', 'weekly-recap', 'staff'];


    // 为“需要回复”按钮添加 active 类
    api.modifyClass('component:navigation-item', {
        active: Ember.computed("contentFilterMode", "filterMode", function () {
            let contentFilterMode = this.get('content').get('filterMode');
            if (window.location.search && window.location.search.split('&')[0] === search_query.split('&')[0]) {
                return contentFilterMode === "needsreply";
            } else {
                return this._super(contentFilterMode, this.get('filterMode'));
            }
        }),
    });

    // 移除 max_posts 过滤器和标签过滤器
    api.modifyClass('controller:discovery/topics', {
        resetParams: function () {
            this.setProperties({max_posts: null});
            this.setProperties({tags: null});
            this._super();
        }
    });

    Discourse.ExternalNavItem = Discourse.NavItem.extend({
        href: function () {
            return this.get('href');
        }.property("href")
    });

    Discourse.NavItem.reopenClass({
        buildList: function (category, args) {
            let list = this._super(category, args),
                tag = args.tagId,
                needsreplyHref;

            if (!category) { // 没有分类
                needsreplyHref = tag ? '/latest/' + search_query + '&tags=' + tag : '/latest/' + search_query; // 如果有标签,则构建包含标签的 href,否则回退到最新视图和搜索查询
            }
            else if (excludeList.indexOf(category.slug) != -1) { // 分类在排除列表中,不执行任何操作
                return list; // 返回列表,不创建自定义导航项
            }
            else if (!category.parentCategory) { // 不是子分类
                needsreplyHref = tag ? '/c/' + category.slug + search_query + '&tags=' + tag : '/c/' + category.slug + search_query; // 如果有标签,则构建包含标签和分类的 href,否则回退到搜索查询等
            } else { // 是子分类
                needsreplyHref = tag ? '/c/' + category.parentCategory.slug + '/' + category.slug + search_query + '&tags=' + tag :
                    '/c/' + category.parentCategory.slug + '/' + category.slug + search_query; // 如果有标签,则构建包含标签、子分类和分类的 href,否则回退到搜索查询等
            }
            list.push(Discourse.ExternalNavItem.create({href: needsreplyHref, name: 'needsreply'}));
            return list;
        }
    });
</script>

JS 控制台中出现了一个错误:

进一步调查后,我发现了一篇关于 Discourse.NavItem 已被弃用的帖子:

对于在不使用已弃用的 NavItem 类的情况下重写此代码,有什么建议吗?

2 个赞