大家好,
我在调查为什么在 Glimmer 帖子流迁移之后,警告类私信的首帖丢失了管理员颜色样式,并想分享一下我的发现——这看起来像是一个小疏忽,而不是有意为之的更改(至少在代码层面是这样)。
问题所在
在 post.gjs(第 436 行) 中,管理员 CSS 类是根据以下条件应用的:
(if
(or @post.isModeratorAction (and @post.isWarning @post.firstPost))
"post--moderator moderator"
"post--regular regular"
)
@post.isModeratorAction 工作正常——它是 Post 模型上的一个正确 getter。但 @post.isWarning 在 Post 模型上根本不存在。
那里没有定义 isWarning 属性、getter 或 tracked 字段。因此,条件 (and @post.isWarning @post.firstPost) 始终评估为 false,moderator 类永远不会应用于警告类私信的首帖。
之前的工作方式
在旧的 widget 系统中,transformPost(transform-post.js)明确将主题级标志映射到帖子属性:
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:
get isWarning() {
return this.topic?.is_warning;
}
我想确认一下团队的意见——这看起来像是 Glimmer 迁移中的疏忽,还是有意为之?无论如何,post.gjs 中对 @post.isWarning 的无效引用可能值得解决。
谢谢!