mirror of
https://github.com/hanzoai/forum.git
synced 2026-09-30 21:51:19 +00:00
* `@ember/owner` instead of `@ember/application`
* `discourse-i18n` instead of `I18n`
* `{ service } from "@ember/service"` instead of `inject as service`
34 lines
818 B
JavaScript
34 lines
818 B
JavaScript
import { getOwner } from "@ember/owner";
|
|
|
|
export function extractCurrentTopicInfo(context) {
|
|
const topic = getOwner(context).lookup("controller:topic")?.model;
|
|
|
|
if (!topic) {
|
|
return;
|
|
}
|
|
|
|
const info = { context_topic_id: topic.id };
|
|
const currentPostNumber = topic.currentPost;
|
|
const posts = topic.postStream.posts;
|
|
|
|
const currentPost = posts.find(
|
|
(post) => post.post_number === currentPostNumber
|
|
);
|
|
const previousPost = posts.findLast(
|
|
(post) =>
|
|
!post.hidden && !post.deleted_at && post.post_number < currentPostNumber
|
|
);
|
|
const nextPost = posts.find(
|
|
(post) =>
|
|
!post.hidden && !post.deleted_at && post.post_number > currentPostNumber
|
|
);
|
|
|
|
info.context_post_ids = [
|
|
previousPost?.id,
|
|
currentPost?.id,
|
|
nextPost?.id,
|
|
].filter(Boolean);
|
|
|
|
return info;
|
|
}
|