# 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:** 1\
**Showing post:** 4

<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` 的无效引用可能值得解决。

谢谢！

---

_[View the full topic](https://meta.discourse.org/t/op-of-warnings-not-highlighted-with-staff-color/380993)._
