# OP的警告未用Staff Color高亮显示

**URL:** <https://meta.discourse.org/t/op-of-warnings-not-highlighted-with-staff-color/380993>\
**Category:** Bug\
**Tags:** fixed\
**Created:** [2025年八月30日 15:32 UTC](https://meta.discourse.org/t/op-of-warnings-not-highlighted-with-staff-color/380993 "2025-08-30T15:32:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![littleD](https://avatars.discourse-cdn.com/v4/letter/l/7bcc69/32.png) [@littleD](https://meta.discourse.org/u/littleD)\
**Post date:** [2025年八月30日 15:32 UTC](https://meta.discourse.org/t/op-of-warnings-not-highlighted-with-staff-color/380993/1 "2025-08-30T15:32:15Z")

</div>

**优先级/严重性** : normal

**平台** : at least on desktop & mobile

**描述** : 当版主向用户发送警告时，我记得在至少一年前的 Discourse 版本中，警告的 OP 应该以 Staff Color 背景高亮显示。但是在使用 Discourse v3.5.0.beta9 时，OP 具有正常的背景。

**可复现步骤** : 在 Discourse v3.5.0.beta9 上向用户发送警告。

---

<div class="post-metadata">

**Author:** ![Banson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/banson/32/454313_2.png) [@Banson](https://meta.discourse.org/u/Banson)\
**Post date:** [2025年八月30日 17:16 UTC](https://meta.discourse.org/t/op-of-warnings-not-highlighted-with-staff-color/380993/2 "2025-08-30T17:16:25Z")

</div>

同样的问题。不知道是 bug 还是故意的。

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2025年八月31日 23:35 UTC](https://meta.discourse.org/t/op-of-warnings-not-highlighted-with-staff-color/380993/3 "2025-08-31T23:35:15Z")

</div>

我觉得这可能是一个故意的更改，@hugh 可能会知道。

---

<div class="post-metadata">

**Author:** ![littleD](https://avatars.discourse-cdn.com/v4/letter/l/7bcc69/32.png) [@littleD](https://meta.discourse.org/u/littleD)\
**Post date:** [2026年六月28日 15:10 UTC](https://meta.discourse.org/t/op-of-warnings-not-highlighted-with-staff-color/380993/4 "2026-06-28T15:10:23Z")

</div>

大家好，

我在调查为什么在 Glimmer 帖子流迁移之后，警告类私信的首帖丢失了管理员颜色样式，并想分享一下我的发现——这看起来像是一个小疏忽，而不是有意为之的更改（至少在代码层面是这样）。

**问题所在**

在 [`post.gjs`（第 436 行）](https://github.com/discourse/discourse/blob/c69722346c4b996c26198e19c52ac4b0f3fec6c2/frontend/discourse/app/components/post.gjs#L435-L439) 中，管理员 CSS 类是根据以下条件应用的：

```hbs
(if
  (or @post.isModeratorAction (and @post.isWarning @post.firstPost))
  "post--moderator moderator"
  "post--regular regular"
)

```

`@post.isModeratorAction` 工作正常——它是 Post 模型上的一个正确 getter。但 `@post.isWarning` 在 [Post](https://github.com/discourse/discourse/blob/c69722346c4b996c26198e19c52ac4b0f3fec6c2/frontend/discourse/app/models/post.js) 模型上根本不存在。

那里没有定义 `isWarning` 属性、getter 或 tracked 字段。因此，条件 `(and @post.isWarning @post.firstPost)` 始终评估为 `false`，`moderator` 类永远不会应用于警告类私信的首帖。

**之前的工作方式**

在旧的 widget 系统中，`transformPost`（`transform-post.js`）明确将主题级标志映射到帖子属性：

```javascript
postAtts.isWarning = topic.is_warning;

```

然后 `widgets/post.js` 检查 `attrs.isWarning && attrs.firstPost` 以应用 `moderator` 类。这个桥梁在 Glimmer 迁移过程中丢失了。

**我的看法**

由于 `post.gjs` 主动引用了 `@post.isWarning`，似乎意图是保留这种行为。如果从警告中移除管理员颜色是有意为之，那么 `post.gjs` 中的 `(and @post.isWarning @post.firstPost)` 分支就是死代码，可以清理。如果这是一个 bug（鉴于旧的 widget 代码，这似乎更有可能），修复方法就是在 Post 模型上添加一个小 getter：

```javascript
get isWarning() {
  return this.topic?.is_warning;
}

```

我想确认一下团队的意见——这看起来像是 Glimmer 迁移中的疏忽，还是有意为之？无论如何，`post.gjs` 中对 `@post.isWarning` 的无效引用可能值得解决。

谢谢！

---

<div class="post-metadata">

**Author:** ![Architect](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/architect/32/520575_2.png) [@Architect](https://meta.discourse.org/u/Architect)\
**Post date:** [2026年六月30日 02:15 UTC](https://meta.discourse.org/t/op-of-warnings-not-highlighted-with-staff-color/380993/5 "2026-06-30T02:15:45Z")

</div>

代码的编写方式很有趣，希望团队中有人能回复你关于这是否是疏忽还是出于其他原因的疑问。

---

<div class="post-metadata">

**Author:** ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)\
**Post date:** [2026年六月30日 14:04 UTC](https://meta.discourse.org/t/op-of-warnings-not-highlighted-with-staff-color/380993/6 "2026-06-30T14:04:06Z")

</div>

报告很棒，谢谢，正如你所描述的那样。我正在这里应用修复：

> <https://github.com/discourse/discourse/pull/41293>
>
> Reported here: https://meta.discourse.org/t/official-warning-pm-notification-fea…ture/387448/8?u=awesomerobot
> 
> We had \`isWarning\`, but it wasn't wired up to anything after the glimmer migration so it never activated to add the moderator color to warnings
> https://github.com/discourse/discourse/blob/8dd0a9c73627a782bf163d3f590da5bb67a4bc3c/frontend/discourse/app/components/post.gjs#L436-L437
> 
> this adds the getter so the correct class is added to warning PMs and we get the color 
> 
> Before:
> \<img width="700" alt="image" src="https://github.com/user-attachments/assets/309df242-25b2-4013-910f-31ddafae6ca4" /\>
> 
> 
> 
> After:
> \<img width="700" alt="image" src="https://github.com/user-attachments/assets/fa3139b8-7ce0-48e5-bc8c-345d30f8d99e" /\>
> 
> included a test to avoid future regressions

---

<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:** [2026年七月2日 14:12 UTC](https://meta.discourse.org/t/op-of-warnings-not-highlighted-with-staff-color/380993/7 "2026-07-02T14:12:16Z")

</div>


