隐藏被忽略用户的帖子列表的潜在方法?

是否可以通过 API 调用获取用户忽略的用户列表,并在渲染话题列表之前隐藏或移除包含该用户 ID 的话题?

1 个赞

这是我目前的实现:

灵感来源于:
https://meta.discourse.org/t/topics-created-by-ignored-users-showing-on-homepage/170366/14

并配合这个主题组件:

它同样适用于移动端。

另外,如果你将这一行:

修改为:

<a href="{{topic.lastPostUrl}}" data-user-card="{{topic.last_poster_username}}" data-user-id="{{topic.creator.username}}">{{avatar topic.lastPosterUser imageSize="large"}}</a>

并将我的代码在以下位置:
https://github.com/notedboi/Discourse-Hide-Ignored-Users/blob/main/common/head_tag.html#L13

修改为:

  let tr = $('*[data-user-id="' + ignored[u] + '"]');

你就可以在移除由被忽略用户创建的帖子的同时,保留最后发帖人的头像和卡片视图。

我唯一的担忧是脚本会每 500 毫秒检查一次,可能会占用过多内存。

3 个赞

我也在研究如何从移动端分类主题中移除被忽略的用户。

<script type="text/x-handlebars" data-template-name="components/mobile-category-topic">
<td class="main-link" data-user-id="{{topic.creator.username}}">
  <div class="topic-inset" >
    {{raw "topic-status" topic=topic}}
    {{topic-link topic}}
    {{#if topic.unseen}}
      <span class="badge-notification new-topic"></span>
    {{/if}}
    <span class={{cold-age-class topic.last_posted_at}} title={{raw-date topic.last_posted_at}}>{{format-age topic.last_posted_at}}</span>
  </div>
</td>
<td class="num posts">{{raw "list/post-count-or-badges" topic=topic postBadgesEnabled="true"}}</td>
</script>

当我尝试在这个视图中添加 data-user-id 时,它不起作用,我是不是找错了模板?


更新:我看到问题了,从 category.topic 传递过来的 topic 对象不包含主题创建者的 ID,而且 topic 对象中的任何属性都无法用作移除主题的标记,我被卡住了。任何帮助都将不胜感激 :rofl:!

1 个赞

我正在尝试更新它并避免使用 setInterval,但以防有人想使用它,上一个版本同时支持 主题缩略图主题列表摘要

您的代码似乎不起作用,并且导致论坛运行非常缓慢。有什么想法吗?@th21

也许它太旧了,无法使用,我做了一个新组件,如果您想尝试的话。\n\nhttps://github.com/notedboi/discourse-ignore-plus\n\n它基于\nhttps://meta.discourse.org/t/need-help-finding-why-topic-list-not-updating-after-click-new-topic-reply-alert/215036

2 个赞

我使用您的组件已经很长时间了,我认为它应该成为 Discourse 核心的一部分,非常感谢您的创造。不幸的是,它现在被标记出来,因为它需要更新以兼容新的 Glimmer 主题列表:

我会看一下

2 个赞