diff --git a/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs b/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs
index bd580190d06..6b60ea68558 100644
--- a/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs
+++ b/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs
@@ -10,6 +10,18 @@ import i18n from "discourse-common/helpers/i18n";
import { avatarImg } from "discourse-common/lib/avatar-utils";
export default class TopicMapSummary extends Component {
+ get linksCount() {
+ return this.args.topicDetails.links?.length ?? 0;
+ }
+
+ get createdByUsername() {
+ return this.args.topicDetails.created_by?.username;
+ }
+
+ get lastPosterUsername() {
+ return this.args.topicDetails.last_poster?.username;
+ }
+
get toggleMapButton() {
return {
title: this.args.collapsed
@@ -25,20 +37,20 @@ export default class TopicMapSummary extends Component {
get shouldShowParticipants() {
return (
this.args.collapsed &&
- this.args.postAttrs.topicPostsCount > 2 &&
- this.args.postAttrs.participants &&
- this.args.postAttrs.participants.length > 0
+ this.args.topic.posts_count > 2 &&
+ this.args.topicDetails.participants &&
+ this.args.topicDetails.participants.length > 0
);
}
get createdByAvatar() {
return htmlSafe(
avatarImg({
- avatarTemplate: this.args.postAttrs.createdByAvatarTemplate,
+ avatarTemplate: this.args.topicDetails.created_by?.avatar_template,
size: "tiny",
title:
- this.args.postAttrs.createdByName ||
- this.args.postAttrs.createdByUsername,
+ this.args.topicDetails.created_by?.name ||
+ this.args.topicDetails.created_by?.username,
})
);
}
@@ -46,11 +58,11 @@ export default class TopicMapSummary extends Component {
get lastPostAvatar() {
return htmlSafe(
avatarImg({
- avatarTemplate: this.args.postAttrs.lastPostAvatarTemplate,
+ avatarTemplate: this.args.topicDetails.last_poster?.avatar_template,
size: "tiny",
title:
- this.args.postAttrs.lastPostName ||
- this.args.postAttrs.lastPostUsername,
+ this.args.topicDetails.last_poster?.name ||
+ this.args.topicDetails.last_poster?.username,
})
);
}
@@ -72,71 +84,67 @@ export default class TopicMapSummary extends Component {
{{this.createdByAvatar}}
-
+
-
+
{{i18n "last_reply_lowercase"}}
{{this.lastPostAvatar}}
-
+
- {{number @postAttrs.topicReplyCount noTitle="true"}}
+ {{number @topic.replyCount noTitle="true"}}
{{i18n
"replies_lowercase"
- count=@postAttrs.topicReplyCount
+ count=@topic.replyCount
}}
- {{number
- @postAttrs.topicViews
- noTitle="true"
- class=@postAttrs.topicViewsHeat
- }}
+ {{number @topic.views noTitle="true" class=@topic.viewsHeat}}
{{i18n
"views_lowercase"
- count=@postAttrs.topicViews
+ count=@topic.views
}}
- {{#if (gt @postAttrs.participantCount 0)}}
+ {{#if (gt @topic.participant_count 0)}}
- {{number @postAttrs.participantCount noTitle="true"}}
+ {{number @topic.participant_count noTitle="true"}}
{{i18n
"users_lowercase"
- count=@postAttrs.participantCount
+ count=@topic.participant_count
}}
{{/if}}
- {{#if (gt @postAttrs.topicLikeCount 0)}}
+ {{#if (gt @topic.like_count 0)}}
- {{number @postAttrs.topicLikeCount noTitle="true"}}
+ {{number @topic.like_count noTitle="true"}}
{{i18n
"likes_lowercase"
- count=@postAttrs.topicLikeCount
+ count=@topic.like_count
}}
{{/if}}
- {{#if (gt @postAttrs.topicLinkCount 0)}}
+ {{#if (gt this.linksCount 0)}}
- {{number @postAttrs.topicLinkCount noTitle="true"}}
+ {{number this.linksCount noTitle="true"}}
{{i18n
"links_lowercase"
- count=@postAttrs.topicLinkCount
+ count=this.linksCount
}}
{{/if}}
@@ -144,8 +152,8 @@ export default class TopicMapSummary extends Component {
{{#if this.shouldShowParticipants}}
{{/if}}
diff --git a/app/assets/javascripts/discourse/app/widgets/post.js b/app/assets/javascripts/discourse/app/widgets/post.js
index 36e69bb76b4..69a2e7591c7 100644
--- a/app/assets/javascripts/discourse/app/widgets/post.js
+++ b/app/assets/javascripts/discourse/app/widgets/post.js
@@ -755,7 +755,10 @@ createWidget("post-body", {
this,
"div.topic-map",
hbs`
`,
{
- postAttrs: attrs,
+ model: attrs.topic,
+ topicDetails: attrs.topic.get("details"),
+ postStream: attrs.topic.postStream,
+ showPMMap: attrs.showPMMap,
cancelFilter: () => this.sendWidgetAction("cancelFilter"),
showTopReplies: () => this.sendWidgetAction("showTopReplies"),
collapseSummary: () => this.sendWidgetAction("collapseSummary"),
diff --git a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-test.js b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-test.js
index 5faadad1167..c77a6344ce8 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-test.js
@@ -780,10 +780,16 @@ module("Integration | Component | Widget | post", function (hooks) {
});
test("topic map - few posts", async function (assert) {
+ const store = getOwner(this).lookup("service:store");
+ const topic = store.createRecord("topic", { id: 123 });
+ topic.details.set("participants", [
+ { username: "eviltrout" },
+ { username: "codinghorror" },
+ ]);
this.set("args", {
+ topic,
showTopicMap: true,
topicPostsCount: 2,
- participants: [{ username: "eviltrout" }, { username: "codinghorror" }],
});
await render(hbs`
`);
@@ -794,16 +800,19 @@ module("Integration | Component | Widget | post", function (hooks) {
});
test("topic map - participants", async function (assert) {
+ const store = getOwner(this).lookup("service:store");
+ const topic = store.createRecord("topic", { id: 123, posts_count: 10 });
+ topic.postStream.setProperties({ userFilters: ["sam", "codinghorror"] });
+ topic.details.set("participants", [
+ { username: "eviltrout" },
+ { username: "codinghorror" },
+ { username: "sam" },
+ { username: "ZogStrIP" },
+ ]);
+
this.set("args", {
+ topic,
showTopicMap: true,
- topicPostsCount: 10,
- participants: [
- { username: "eviltrout" },
- { username: "codinghorror" },
- { username: "sam" },
- { username: "ZogStrIP" },
- ],
- userFilters: ["sam", "codinghorror"],
});
await render(hbs`
`);
@@ -816,17 +825,17 @@ module("Integration | Component | Widget | post", function (hooks) {
});
test("topic map - links", async function (assert) {
- this.set("args", {
- showTopicMap: true,
- topicLinks: [
- { url: "http://link1.example.com", clicks: 0 },
- { url: "http://link2.example.com", clicks: 0 },
- { url: "http://link3.example.com", clicks: 0 },
- { url: "http://link4.example.com", clicks: 0 },
- { url: "http://link5.example.com", clicks: 0 },
- { url: "http://link6.example.com", clicks: 0 },
- ],
- });
+ const store = getOwner(this).lookup("service:store");
+ const topic = store.createRecord("topic", { id: 123 });
+ topic.details.set("links", [
+ { url: "http://link1.example.com", clicks: 0 },
+ { url: "http://link2.example.com", clicks: 0 },
+ { url: "http://link3.example.com", clicks: 0 },
+ { url: "http://link4.example.com", clicks: 0 },
+ { url: "http://link5.example.com", clicks: 0 },
+ { url: "http://link6.example.com", clicks: 0 },
+ ]);
+ this.set("args", { topic, showTopicMap: true });
await render(hbs`
`);
@@ -845,7 +854,9 @@ module("Integration | Component | Widget | post", function (hooks) {
});
test("topic map - no summary", async function (assert) {
- this.set("args", { showTopicMap: true });
+ const store = getOwner(this).lookup("service:store");
+ const topic = store.createRecord("topic", { id: 123 });
+ this.set("args", { topic, showTopicMap: true });
await render(hbs`
`);
@@ -853,7 +864,9 @@ module("Integration | Component | Widget | post", function (hooks) {
});
test("topic map - has top replies summary", async function (assert) {
- this.set("args", { showTopicMap: true, hasTopRepliesSummary: true });
+ const store = getOwner(this).lookup("service:store");
+ const topic = store.createRecord("topic", { id: 123, has_summary: true });
+ this.set("args", { topic, showTopicMap: true });
this.set("showTopReplies", () => (this.summaryToggled = true));
await render(
@@ -867,11 +880,15 @@ module("Integration | Component | Widget | post", function (hooks) {
});
test("pm map", async function (assert) {
+ const store = getOwner(this).lookup("service:store");
+ const topic = store.createRecord("topic", { id: 123 });
+ topic.details.set("allowed_users", [
+ EmberObject.create({ username: "eviltrout" }),
+ ]);
this.set("args", {
+ topic,
showTopicMap: true,
showPMMap: true,
- allowedGroups: [],
- allowedUsers: [EmberObject.create({ username: "eviltrout" })],
});
await render(hbs`
`);