# 隐藏导入帖中的用户 ping

**URL:** https://meta.discourse.org/t/suppress-user-pings-in-imported-posts/285883
**Category:** Support
**Created:** [2023年十一月17日 18:40 UTC](https://meta.discourse.org/t/suppress-user-pings-in-imported-posts/285883 "2023-11-17T18:40:05Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![winston-yallow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/winston-yallow/32/339990_2.png) [@winston-yallow](https://meta.discourse.org/u/winston-yallow)
#### Post date: [2023年十一月17日 18:40 UTC](https://meta.discourse.org/t/suppress-user-pings-in-imported-posts/285883/1 "2023-11-17T18:40:05Z")

</div>

我们正在导入大量帖子，内容经常包含类似 `@global` 的文本（我们的 discourse 实例主题与编程相关，而 `@` 是该语言中的一个符号）。

有没有一种干净优雅的方法可以阻止 ping 用户？我不介意在导入前预处理帖子。

作为一种有点粗糙的解决方法，我发现如果在 `@` 后面插入一个空的 bbcode 标签（例如 `@[b][/b]global`）可以起作用。但这感觉不是一个很好的解决方案，并且需要我解析/标记 markdown，因为如果字符串在代码块内，就不应该插入 bbcode。所以这不是一个好的解决方案。零宽空格也不是一个解决方案，因为它会导致用户将代码片段复制到自己的源代码中时出现奇怪的错误。

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2023年十一月17日 23:47 UTC](https://meta.discourse.org/t/suppress-user-pings-in-imported-posts/285883/2 "2023-11-17T23:47:12Z")

</div>

如果它在代码块中，那不是问题。如果您的代码块可以确保始终在代码块中，那么您就处于有利地位。不过，您需要运行一个真正的解析器才能知道何时处于代码块中。

哦，或者在导入数据时关闭“允许用户提及其他用户”设置。

---

<div class="post-metadata">

### Author: ![winston-yallow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/winston-yallow/32/339990_2.png) [@winston-yallow](https://meta.discourse.org/u/winston-yallow)
#### Post date: [2023年十一月17日 23:51 UTC](https://meta.discourse.org/t/suppress-user-pings-in-imported-posts/285883/3 "2023-11-17T23:51:07Z")

</div>

> [@pfaffman](#):
>
> If it’s in a code block it’s not a problem.

当然，如果 `@name` 在代码块中，那就不是问题。问题在于如何检测它是否在代码块中，以便在代码块外通过在 `@` 和 `name` 之间插入不可见的 `[b][/b]` 标签来阻止 ping。这确实需要一个完整的 markdown 解析器/分词器。

> [@pfaffman](#):
>
> Oh, or turn off the `Allow users to mention other users` setting while you import the data.

嗯，在重新烘烤帖子时，这是否仍然适用，或者会导致随机 ping？

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2023年十一月18日 00:04 UTC](https://meta.discourse.org/t/suppress-user-pings-in-imported-posts/285883/4 "2023-11-18T00:04:32Z")

</div>

> [@winston-yallow](#):
>
> 帖子之后被重新烘烤时，这是否仍然适用？

我很确定当它们被重新烘烤时，会有一个开关来避免颠簸和提及，但我既没有检查过代码，也没有尝试过。

---

<div class="post-metadata">

### Author: ![winston-yallow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/winston-yallow/32/339990_2.png) [@winston-yallow](https://meta.discourse.org/u/winston-yallow)
#### Post date: [2023年十一月18日 00:08 UTC](https://meta.discourse.org/t/suppress-user-pings-in-imported-posts/285883/5 "2023-11-18T00:08:23Z")

</div>

据我所知，没有什么可以阻止 ping，这些更改会直接发布给客户端（但我绝不是 ruby 或 discourse 的专家，所以如果我错了，请纠正我）：

> <https://github.com/discourse/discourse/blob/main/app/models/post.rb#L755>

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2023年十一月18日 00:30 UTC](https://meta.discourse.org/t/suppress-user-pings-in-imported-posts/285883/6 "2023-11-18T00:30:41Z")

</div>

我认为这个

> <https://github.com/discourse/discourse/blob/main/app/models/post.rb#L773>

我认为绕过“bump”也会阻止“mentors”再次发生，但“trigger post process”有

```
`new_post: false,`

```

所以我认为你是安全的。

---

<div class="post-metadata">

### Author: ![winston-yallow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/winston-yallow/32/339990_2.png) [@winston-yallow](https://meta.discourse.org/u/winston-yallow)
#### Post date: [2023年十一月18日 00:32 UTC](https://meta.discourse.org/t/suppress-user-pings-in-imported-posts/285883/7 "2023-11-18T00:32:05Z")

</div>

哦，好主意，我错过了那部分！太好了，我就会这么做 ✨

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2023年十一月18日 00:49 UTC](https://meta.discourse.org/t/suppress-user-pings-in-imported-posts/285883/8 "2023-11-18T00:49:49Z")

</div>

并且导入脚本可能已经设置了此项。我不认为导入会引起大量的通知。

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2023年十二月18日 00:50 UTC](https://meta.discourse.org/t/suppress-user-pings-in-imported-posts/285883/9 "2023-12-18T00:50:14Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
