From cb0a286ffc0ba46b9b694261b73a5462925d5320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Saquetim?= Date: Mon, 1 Dec 2025 17:01:08 -0300 Subject: [PATCH 1/2] DEV: Replace deprecated `reads` with `dependentKeyCompat` in `post-stream.js` Update the `PostStream` class to replace the deprecated `@reads` decorator with `@dependentKeyCompat` for the `lastPostCreatedAt` computed property. This change ensures compatibility with future Ember versions and maintains the expected behavior of the property. The `noContent` computed property was also updated to use `@dependentKeyCompat`. This refactor enhances code stability and prepares the codebase for upcoming Ember updates. --- .../discourse/models/post-stream.js | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/assets/javascripts/discourse/models/post-stream.js b/assets/javascripts/discourse/models/post-stream.js index 99b00d5..913ba44 100644 --- a/assets/javascripts/discourse/models/post-stream.js +++ b/assets/javascripts/discourse/models/post-stream.js @@ -1,6 +1,6 @@ import { tracked } from "@glimmer/tracking"; import EmberObject from "@ember/object"; -import { reads } from "@ember/object/computed"; +import { dependentKeyCompat } from "@ember/object/compat"; import { ajax } from "discourse/lib/ajax"; import { addUniqueValuesToArray } from "discourse/lib/array-tools"; import { trackedArray } from "discourse/lib/tracked-tools"; @@ -12,14 +12,17 @@ import RestModel from "discourse/models/rest"; // component (in core as well) which expects a `UserStream` instance. export default class PostStream extends RestModel { - @tracked loading = false; - @tracked itemsLoaded = 0; @tracked canLoadMore = true; - + @tracked itemsLoaded = 0; + @tracked loading = false; @trackedArray content = []; - @reads("content.lastObject.created_at") lastPostCreatedAt; + @dependentKeyCompat + get lastPostCreatedAt() { + return this.content.at(-1).created_at; + } + @dependentKeyCompat get noContent() { return !this.loading && this.content.length === 0; } @@ -31,16 +34,13 @@ export default class PostStream extends RestModel { this.loading = true; const data = {}; - if (this.lastPostCreatedAt) { data.created_before = this.lastPostCreatedAt; } - try { const content = await ajax(`/follow/posts/${this.user.username}`, { data, }); - const streamItems = content.posts.map((post) => { return EmberObject.create({ title: post.topic.title, @@ -60,12 +60,9 @@ export default class PostStream extends RestModel { truncated: post.truncated, }); }); - - const { hasMore } = content.extras; addUniqueValuesToArray(this.content, streamItems); - this.itemsLoaded = this.content.length; - this.canLoadMore = hasMore; + this.canLoadMore = content.extras.has_more; } finally { this.loading = false; } From 0e8f8bd2f1098ac2ca2a934ec6adeb921af8850d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Saquetim?= <1108771+megothss@users.noreply.github.com> Date: Tue, 2 Dec 2025 15:28:51 -0300 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Jarek Radosz --- assets/javascripts/discourse/models/post-stream.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/models/post-stream.js b/assets/javascripts/discourse/models/post-stream.js index 913ba44..d0e2181 100644 --- a/assets/javascripts/discourse/models/post-stream.js +++ b/assets/javascripts/discourse/models/post-stream.js @@ -19,7 +19,7 @@ export default class PostStream extends RestModel { @dependentKeyCompat get lastPostCreatedAt() { - return this.content.at(-1).created_at; + return this.content.at(-1)?.created_at; } @dependentKeyCompat