Skip to content

A platform for community discussion. Free, open, simple.

FIX: Prevent left-over markup for old hidden post notices (#35311)

Sérgio Saquetimeb54cbd995c6
diff --git a/app/assets/javascripts/discourse/app/components/post.gjs b/app/assets/javascripts/discourse/app/components/post.gjs
index 355b171200b..8447192ad6b 100644
--- a/app/assets/javascripts/discourse/app/components/post.gjs
+++ b/app/assets/javascripts/discourse/app/components/post.gjs
@@ -491,7 +491,7 @@ export default class Post extends Component {
</section>
</div>
{{/if}}
- {{#if (and (not @post.deletedAt) @post.notice)}}
+ {{#if (PostNotice.shouldRender @post this.siteSettings)}}
<div class="post__row row">
<PostNotice @post={{@post}} />
</div>
diff --git a/app/assets/javascripts/discourse/app/components/post/notice.gjs b/app/assets/javascripts/discourse/app/components/post/notice.gjs
index f681cfed3cb..fa090954bb1 100644
--- a/app/assets/javascripts/discourse/app/components/post/notice.gjs
+++ b/app/assets/javascripts/discourse/app/components/post/notice.gjs
@@ -1,5 +1,4 @@
import Component from "@glimmer/component";
-import { service } from "@ember/service";
import { dasherize } from "@ember/string";
import concatClass from "discourse/helpers/concat-class";
import { applyValueTransformer } from "discourse/lib/transformer";
@@ -14,7 +13,16 @@ const POST_NOTICE_COMPONENTS = {
};
export default class PostNotice extends Component {
- @service siteSettings;
+ static shouldRender(post, siteSettings) {
+ if (!post.notice || post.deletedAt) {
+ return false;
+ }
+
+ const postAge = new Date() - new Date(post.created_at);
+ const maxAge = siteSettings.old_post_notice_days * 86400000;
+
+ return post.notice.type === "custom" || postAge <= maxAge;
+ }
get Component() {
return applyValueTransformer(
@@ -28,17 +36,9 @@ export default class PostNotice extends Component {
return this.args.post.notice.type;
}
- get shouldRender() {
- const postAge = new Date() - new Date(this.args.post.created_at);
- const maxAge = this.siteSettings.old_post_notice_days * 86400000;
- return this.args.post.notice.type === "custom" || postAge <= maxAge;
- }
-
<template>
- {{#if this.shouldRender}}
- <div class={{concatClass "post-notice" (dasherize this.type)}}>
- <this.Component @notice={{@post.notice}} @post={{@post}} />
- </div>
- {{/if}}
+ <div class={{concatClass "post-notice" (dasherize this.type)}}>
+ <this.Component @notice={{@post.notice}} @post={{@post}} />
+ </div>
</template>
}