FIX: Use created_at if last_posted_at is null (#13668)

FIX: Use created_at if last_posted_at is null (#13668)

Topic timeline showed Jan 1970 as last posted time if all posts of a topic were deleted or whispers.

diff --git a/app/assets/javascripts/discourse/app/widgets/topic-timeline.js b/app/assets/javascripts/discourse/app/widgets/topic-timeline.js
index 18f8573..0314981 100644
--- a/app/assets/javascripts/discourse/app/widgets/topic-timeline.js
+++ b/app/assets/javascripts/discourse/app/widgets/topic-timeline.js
@@ -539,11 +539,14 @@ export default createWidget("topic-timeline", {
     }
 
     if (displayTimeLineScrollArea) {
-      const bottomAge = relativeAge(new Date(topic.last_posted_at), {
-        addAgo: true,
-        defaultFormat: timelineDate,
-      });
-      let scroller = [
+      const bottomAge = relativeAge(
+        new Date(topic.last_posted_at || topic.created_at),
+        {
+          addAgo: true,
+          defaultFormat: timelineDate,
+        }
+      );
+      const scroller = [
         h(
           "div.timeline-date-wrapper",
           this.attach("link", {
diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-timeline-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-timeline-test.js
new file mode 100644
index 0000000..9f43748
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/acceptance/topic-timeline-test.js
@@ -0,0 +1,336 @@
+import { visit } from "@ember/test-helpers";
+import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
+import { test } from "qunit";
+
+acceptance("Topic Timeline", function (needs) {
+  needs.user();
+
+  needs.pretender((server, helper) => {
+    server.get("/t/129.json", () => {
+      return helper.response({
+        post_stream: {
+          posts: [
+            {
+              id: 132,
+              name: null,
+              username: "foo",
+              avatar_template:
+                "/letter_avatar_proxy/v4/letter/f/b19c9b/{size}.png",
+              created_at: "2020-07-08T15:03:53.166Z",
+              cooked: "<p>Deleted post</p>",
+              post_number: 1,
+              post_type: 1,
+              updated_at: "2020-07-08T15:04:33.425Z",
+              reply_count: 0,
+              reply_to_post_number: null,
+              quote_count: 0,
+              incoming_link_count: 0,
+              reads: 1,
+              readers_count: 0,
+              score: 0,
+              yours: true,
+              topic_id: 129,
+              topic_slug: "deleted-topic-with-whisper-post",
+              display_username: null,
+              primary_group_name: null,
+              flair_name: null,
+              flair_url: null,
+              flair_bg_color: null,
+              flair_color: null,
+              version: 1,
+              can_edit: true,
+              can_delete: false,
+              can_recover: true,
+              can_wiki: true,
+              read: true,
+              user_title: null,
+              bookmarked: false,
+              actions_summary: [
+                {
+                  id: 3,
+                  can_act: true,
+                },
+                {
+                  id: 4,
+                  can_act: true,
+                },
+                {
+                  id: 8,
+                  can_act: true,
+                },
+                {
+                  id: 7,
+                  can_act: true,
+                },
+              ],
+              moderator: false,
+              admin: true,
+              staff: true,
+              user_id: 7,
+              hidden: false,
+              trust_level: 4,
+              deleted_at: "2020-07-08T15:04:37.544Z",
+              deleted_by: {
+                id: 7,
+                username: "foo",
+                name: null,
+                avatar_template:
+                  "/letter_avatar_proxy/v4/letter/f/b19c9b/{size}.png",
+              },
+              user_deleted: false,
+              edit_reason: null,
+              can_view_edit_history: true,
+              wiki: false,
+              reviewable_id: 0,
+              reviewable_score_count: 0,
+              reviewable_score_pending_count: 0,
+            },
+            {
+              id: 133,
+              name: null,
+              username: "foo",
+              avatar_template:
+                "/letter_avatar_proxy/v4/letter/f/b19c9b/{size}.png",
+              created_at: "2020-07-08T15:04:23.190Z",
+              cooked: "<p>Whisper post</p>",
+              post_number: 2,
+              post_type: 4,
+              updated_at: "2020-07-08T15:04:23.190Z",
+              reply_count: 0,
+              reply_to_post_number: null,
+              quote_count: 0,
+              incoming_link_count: 0,
+              reads: 1,
+              readers_count: 0,
+              score: 0,
+              yours: true,
+              topic_id: 129,
+              topic_slug: "deleted-topic-with-whisper-post",
+              display_username: null,
+              primary_group_name: null,
+              flair_name: null,
+              flair_url: null,
+              flair_bg_color: null,
+              flair_color: null,
+              version: 1,
+              can_edit: true,
+              can_delete: true,
+              can_recover: false,
+              can_wiki: true,
+              read: true,
+              user_title: null,
+              bookmarked: false,
+              actions_summary: [
+                {
+                  id: 3,
+                  can_act: true,
+                },
+                {
+                  id: 4,
+                  can_act: true,
+                },
+                {
+                  id: 8,
+                  can_act: true,
+                },
+                {
+                  id: 7,
+                  can_act: true,
+                },
+              ],
+              moderator: false,
+              admin: true,
+              staff: true,
+              user_id: 7,
+              hidden: false,
+              trust_level: 4,
+              deleted_at: null,
+              user_deleted: false,
+              edit_reason: null,
+              can_view_edit_history: true,
+              wiki: false,
+              reviewable_id: 0,
+              reviewable_score_count: 0,
+              reviewable_score_pending_count: 0,
+            },
+          ],
+          stream: [132, 133],
+        },
+        timeline_lookup: [[1, 0]],
+        suggested_topics: [
+          {
+            id: 7,
+            title: "Welcome to Discourse",
+            fancy_title: "Welcome to Discourse",
+            slug: "welcome-to-discourse",
+            posts_count: 1,
+            reply_count: 0,
+            highest_post_number: 1,
+            image_url: null,
+            created_at: "2020-07-08T14:56:57.424Z",
+            last_posted_at: "2020-07-08T14:56:57.488Z",
+            bumped: true,
+            bumped_at: "2020-07-08T14:56:57.488Z",
+            archetype: "regular",
+            unseen: false,
+            pinned: true,
+            unpinned: null,
+            excerpt:
+              "The first paragraph of this pinned topic will be visible as a welcome message to all new visitors on your homepage. It’s important! \nEdit this into a brief description of your community: \n\nWho is it for?\nWhat can they fi&hellip;",
+            visible: true,
+            closed: false,
+            archived: false,
+            bookmarked: null,
+            liked: null,
+            tags: [],
+            like_count: 0,
+            views: 0,
+            category_id: 1,
+            featured_link: null,
+            posters: [
+              {
+                extras: "latest single",
+                description: "Original Poster, Most Recent Poster",
+                user: {
+                  id: -1,
+                  username: "system",
+                  name: "system",
+                  avatar_template: "/images/discourse-logo-sketch-small.png",
+                },
+              },
+            ],
+          },
+        ],
+        tags: [],
+        id: 129,

[... diff too long, it was truncated ...]

GitHub sha: 2f5e63fd7f8a1598882a35bd216d8eb59bb73d5a

This commit appears in #13668 which was approved by CvX and ZogStriP. It was merged by nbianca.