Skip to content

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

DEV: don't show new user notice after x-time (#34988)

chapoid262ce891b62
diff --git a/app/assets/javascripts/discourse/app/components/post/notice.gjs b/app/assets/javascripts/discourse/app/components/post/notice.gjs
index ecf627391b1..737a657657a 100644
--- a/app/assets/javascripts/discourse/app/components/post/notice.gjs
+++ b/app/assets/javascripts/discourse/app/components/post/notice.gjs
@@ -24,26 +24,21 @@ export default class PostNotice extends Component {
);
}
- get classNames() {
- const classes = [dasherize(this.type)];
-
- if (
- new Date() - new Date(this.args.post.created_at) >
- this.siteSettings.old_post_notice_days * 86400000
- ) {
- classes.push("old");
- }
-
- return classes;
- }
-
get type() {
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 postAge <= maxAge;
+ }
+
<template>
- <div class={{concatClass "post-notice" this.classNames}}>
- <this.Component @notice={{@post.notice}} @post={{@post}} />
- </div>
+ {{#if this.shouldRender}}
+ <div class={{concatClass "post-notice" (dasherize this.type)}}>
+ <this.Component @notice={{@post.notice}} @post={{@post}} />
+ </div>
+ {{/if}}
</template>
}
diff --git a/app/assets/javascripts/discourse/tests/integration/components/post/post-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/post/post-test.gjs
index 9384bd45902..4edf1967890 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/post/post-test.gjs
+++ b/app/assets/javascripts/discourse/tests/integration/components/post/post-test.gjs
@@ -717,7 +717,7 @@ module("Integration | Component | Post", function (hooks) {
await renderComponent(this.post);
- assert.dom(".post-notice.returning-user:not(.old)").hasText(
+ assert.dom(".post-notice.returning-user").hasText(
i18n("post.notice.returning_user", {
user: "codinghorror",
time: "2 days ago",
@@ -732,14 +732,30 @@ module("Integration | Component | Post", function (hooks) {
this.post.username = "codinghorror";
this.post.name = "Jeff";
- this.post.created_at = new Date(2019, 0, 1);
+ this.post.created_at = new Date(); // Use current date to ensure it's within the 14-day limit
this.post.notice = { type: "new_user" };
await renderComponent(this.post);
assert
- .dom(".post-notice.old.new-user")
- .hasText(i18n("post.notice.new_user", { user: "Jeff", time: "Jan '10" }));
+ .dom(".post-notice.new-user")
+ .exists("notice should render for recent posts");
+ });
+
+ test("post notice - not rendered when post is older than old_post_notice_days", async function (assert) {
+ this.siteSettings.old_post_notice_days = 14;
+
+ const twentyDaysAgo = new Date();
+ twentyDaysAgo.setDate(twentyDaysAgo.getDate() - 20);
+
+ this.post.created_at = twentyDaysAgo;
+ this.post.notice = { type: "new_user" };
+
+ await renderComponent(this.post);
+
+ assert
+ .dom(".post-notice.new-user")
+ .doesNotExist("notice should not render for old posts");
});
test("show group request in post", async function (assert) {
diff --git a/app/assets/stylesheets/common/base/topic-post.scss b/app/assets/stylesheets/common/base/topic-post.scss
index d45a3c5937c..75e4631ab6b 100644
--- a/app/assets/stylesheets/common/base/topic-post.scss
+++ b/app/assets/stylesheets/common/base/topic-post.scss
@@ -1532,15 +1532,6 @@ span.mention {
gap: var(--space-2);
}
- &.old {
- background-color: unset;
- color: var(--primary-medium);
-
- .d-icon {
- color: var(--primary-medium);
- }
- }
-
.emoji {
width: 1.5em;
height: 1.5em;
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 7f286ed0d48..2d0b9b3744e 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2578,7 +2578,7 @@ en:
watched_words_regular_expressions: "Allows the use of regular expressions for filtering words. If enabled, this feature groups sensitive words by their case-sensitivity. It then compiles all selected words into a single regular expression, adding word boundaries for regular watched words. Consequently, this regex-based filtering method adds an extra layer of control over content moderation by supporting more sophisticated word patterns. The setting also allows to easily substitute the original text with the replacement of choice."
enable_fast_edit: "Adds a button to the post selection menu to edit a small selection inline."
- old_post_notice_days: "The number of days after which a post notice is considered old. This visually differentiates it from newer notices on the site."
+ old_post_notice_days: "The number of days after which a post notice is considered old. Old notices will be hidden."
new_user_notice_tl: "Minimum trust level required to see new user post notices."
returning_user_notice_tl: "Minimum trust level required to see returning user post notices."
returning_users_days: "How many days should pass before a user is considered to be returning."