A platform for community discussion. Free, open, simple.
FIX: Horizon high-context cards show bump time instead of last-reply time
Jake Goldsboroughfe1f8b5df531
diff --git a/themes/horizon/javascripts/discourse/components/card/high-context-topic-card.gjs b/themes/horizon/javascripts/discourse/components/card/high-context-topic-card.gjsindex 573875af248..b605936bada 100644--- a/themes/horizon/javascripts/discourse/components/card/high-context-topic-card.gjs+++ b/themes/horizon/javascripts/discourse/components/card/high-context-topic-card.gjs@@ -11,7 +11,7 @@ import TopicPostBadges from "discourse/components/topic-post-badges";import TopicStatus from "discourse/components/topic-status";import topicFeaturedLink from "discourse/helpers/topic-featured-link";import { shortDateNoYear } from "discourse/lib/formatter";-import { or } from "discourse/truth-helpers";+import { and, or } from "discourse/truth-helpers";import dAvatar from "discourse/ui-kit/helpers/d-avatar";import { categoryLinkHTML } from "discourse/ui-kit/helpers/d-category-link";import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";@@ -102,6 +102,27 @@ export default class HighContextTopicCard extends Component {}get lastPoster() {+ // When the topic was bumped > 1 day after the last actual post, the+ // bump came from an edit or wiki conversion rather than a reply.+ // Returning null hides the "X replied {time}" line in the template,+ // matching how TopicActivityColumn handles the same case.+ const bumpedLastPostedDaysDiff = moment+ .duration(+ moment(this.args.topic.bumped_at).diff(+ moment(this.args.topic.last_posted_at)+ )+ )+ .asDays();++ if (+ moment(this.args.topic.bumped_at).isAfter(+ this.args.topic.last_posted_at+ ) &&+ bumpedLastPostedDaysDiff > 1+ ) {+ return null;+ }+return {user: this.args.topic.lastPosterUser,username: this.args.topic.last_poster_username,@@ -211,7 +232,7 @@ export default class HighContextTopicCard extends Component {{{#if (or this.hasReplies this.hasAssigned)}}<div class="hc-topic-card__context">- {{#if this.hasReplies}}+ {{#if (and this.hasReplies this.lastPoster)}}<div class="hc-topic-card__last-reply">{{dAvatar this.lastPoster.user imageSize="tiny"}}<span@@ -219,7 +240,7 @@ export default class HighContextTopicCard extends Component {>{{this.lastPoster.username}}</span><span>{{i18n (themePrefix "replied")}}</span><span class="hc-topic-card__time">- {{dFormatDate @topic.bumpedAt leaveAgo="true"}}+ {{dFormatDate @topic.last_posted_at leaveAgo="true"}}</span></div>{{/if}}diff --git a/themes/horizon/test/acceptance/high-context-topic-card-test.gjs b/themes/horizon/test/acceptance/high-context-topic-card-test.gjsnew file mode 100644index 00000000000..253f008bf93--- /dev/null+++ b/themes/horizon/test/acceptance/high-context-topic-card-test.gjs@@ -0,0 +1,47 @@+import { render } from "@ember/test-helpers";+import { module, test } from "qunit";+import Topic from "discourse/models/topic";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import HighContextTopicCard from "../../discourse/components/card/high-context-topic-card";++module(+ "Horizon | Integration | Component | Card | HighContextTopicCard",+ function (hooks) {+ setupRenderingTest(hooks);++ test("shows the last reply line with the actual reply time when a reply is recent", async function (assert) {+ const topic = Topic.create({+ id: 1,+ bumped_at: "2024-06-01T12:00:00Z",+ last_posted_at: "2024-06-01T12:00:00Z",+ last_poster_username: "alice",+ posts_count: 3,+ reply_count: 2,+ });+ await render(+ <template><HighContextTopicCard @topic={{topic}} /></template>+ );+ assert.dom(".hc-topic-card__last-reply").exists();+ assert.dom(".hc-topic-card__last-reply-name").hasText("alice");+ });++ test("hides the last reply line when the topic was bumped more than a day after the last post", async function (assert) {+ // This case represents an OP edit (or wiki conversion) bumping the+ // topic well after the last actual reply. The card used to show+ // "{last_poster} replied {bumped_at}" which read as "replied just+ // now" when the real reply was days earlier.+ const topic = Topic.create({+ id: 1,+ bumped_at: "2024-06-10T12:00:00Z",+ last_posted_at: "2024-06-01T12:00:00Z",+ last_poster_username: "alice",+ posts_count: 3,+ reply_count: 2,+ });+ await render(+ <template><HighContextTopicCard @topic={{topic}} /></template>+ );+ assert.dom(".hc-topic-card__last-reply").doesNotExist();+ });+ }+);