FEATURE: Post notices become old after 14 days. (#7197)

FEATURE: Post notices become old after 14 days. (#7197)

diff --git a/app/assets/javascripts/discourse/widgets/post.js.es6 b/app/assets/javascripts/discourse/widgets/post.js.es6
index a7c0c45..167f95c 100644
--- a/app/assets/javascripts/discourse/widgets/post.js.es6
+++ b/app/assets/javascripts/discourse/widgets/post.js.es6
@@ -432,12 +432,22 @@ createWidget("post-notice", {
   tagName: "div.post-notice",
 
   buildClasses(attrs) {
+    const classes = [];
+
     if (attrs.postNoticeType === "first") {
-      return ["new-user"];
+      classes.push("new-user");
     } else if (attrs.postNoticeType === "returning") {
-      return ["returning-user"];
+      classes.push("returning-user");
+    }
+
+    if (
+      new Date() - new Date(attrs.created_at) >
+      this.siteSettings.old_post_notice_days * 86400000
+    ) {
+      classes.push("old");
     }
-    return [];
+
+    return classes;
   },
 
   html(attrs) {
diff --git a/app/assets/stylesheets/common/base/topic-post.scss b/app/assets/stylesheets/common/base/topic-post.scss
index afa8bc5..8988252 100644
--- a/app/assets/stylesheets/common/base/topic-post.scss
+++ b/app/assets/stylesheets/common/base/topic-post.scss
@@ -867,12 +867,14 @@ a.mention-group {
 
 .post-notice {
   background-color: $tertiary-low;
+  border-top: 1px solid $primary-low;
   color: $primary;
   padding: 0.8em;
-  max-width: calc(
-    #{$topic-body-width} + #{$topic-avatar-width} - #{$topic-body-width-padding} +
-      0.6em
-  );
+  max-width: calc(#{$topic-body-width} + #{$topic-avatar-width} - 0.1em);
+
+  &.old {
+    background-color: unset;
+  }
 
   p {
     display: flex;
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 8b830a6..28a20a7 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1920,6 +1920,7 @@ en:
     watched_words_regular_expressions: "Watched words are regular expressions."
 
     min_post_notice_tl: "Minimum trust level required to see post notices."
+    old_post_notice_days: "Days before post notice becomes old"
     returning_users_days: "How many days should pass before a user is considered to be returning."
 
     default_email_digest_frequency: "How often users receive summary emails by default."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 6ead1d3..d1f07c6 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -828,6 +828,9 @@ posting:
   min_post_notice_tl:
     default: 2
     enum: "TrustLevelSetting"
+  old_post_notice_days:
+    default: 14
+    client: true
   returning_users_days:
     default: 120
 
diff --git a/test/javascripts/widgets/post-test.js.es6 b/test/javascripts/widgets/post-test.js.es6
index 6c0c7fa..8f20559 100644
--- a/test/javascripts/widgets/post-test.js.es6
+++ b/test/javascripts/widgets/post-test.js.es6
@@ -857,16 +857,18 @@ widgetTest("post notice - with username", {
   template: '{{mount-widget widget="post" args=args}}',
   beforeEach() {
     this.siteSettings.prioritize_username_in_ux = true;
+    this.siteSettings.old_post_notice_days = 14;
     this.set("args", {
       postNoticeType: "returning",
-      postNoticeTime: new Date("2010-01-01 12:00:00 UTC"),
+      postNoticeTime: new Date(2010, 0, 1),
       username: "codinghorror",
-      name: "Jeff"
+      name: "Jeff",
+      created_at: new Date()
     });
   },
   test(assert) {
     assert.equal(
-      find(".post-notice.returning-user")
+      find(".post-notice.returning-user:not(.old)")
         .text()
         .trim(),
       I18n.t("post.notice.return", { user: "codinghorror", time: "Jan '10" })
@@ -878,15 +880,17 @@ widgetTest("post notice - with name", {
   template: '{{mount-widget widget="post" args=args}}',
   beforeEach() {
     this.siteSettings.prioritize_username_in_ux = false;
+    this.siteSettings.old_post_notice_days = 14;
     this.set("args", {
       postNoticeType: "first",
       username: "codinghorror",
-      name: "Jeff"
+      name: "Jeff",
+      created_at: new Date(2019, 0, 1)
     });
   },
   test(assert) {
     assert.equal(
-      find(".post-notice.new-user")
+      find(".post-notice.old.new-user")
         .text()
         .trim(),
       I18n.t("post.notice.first", { user: "Jeff", time: "Jan '10" })

GitHub sha: 976ea160

2 Likes