UX: reduce bottom topic map threshold, with protections (#29665)

This commit is contained in:
Kris 2024-11-13 07:58:44 -05:00 committed by GitHub
parent 3df3ad6ed6
commit 9a22d7df7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 5 deletions

View File

@ -28,7 +28,7 @@ const MIN_LIKES_COUNT = 5;
const MIN_PARTICIPANTS_COUNT = 5;
const MIN_USERS_COUNT_FOR_AVATARS = 2;
export const MIN_POSTS_COUNT = 5;
export const MIN_POSTS_COUNT = 3;
export default class TopicMapSummary extends Component {
@service site;

View File

@ -34,6 +34,7 @@ import Composer from "discourse/models/composer";
import Post from "discourse/models/post";
import Topic from "discourse/models/topic";
import TopicTimer from "discourse/models/topic-timer";
import { isTesting } from "discourse-common/config/environment";
import discourseLater from "discourse-common/lib/later";
import { deepMerge } from "discourse-common/lib/object";
import discourseComputed, { bind } from "discourse-common/utils/decorators";
@ -41,6 +42,7 @@ import I18n from "discourse-i18n";
let customPostMessageCallbacks = {};
const RETRIES_ON_RATE_LIMIT = 4;
const MIN_BOTTOM_MAP_WORD_COUNT = 200;
export function resetCustomPostMessageCallbacks() {
customPostMessageCallbacks = {};
@ -233,12 +235,25 @@ export default class TopicController extends Controller.extend(
return Category.findById(categoryId)?.minimumRequiredTags || 0;
}
@discourseComputed("model.posts_count", "model.postStream.loadingFilter")
showBottomTopicMap(postsCount, loading) {
@discourseComputed(
"model.postStream.posts",
"model.word_count",
"model.postStream.loadingFilter"
)
showBottomTopicMap(posts, wordCount, loading) {
// filter out small posts, because they're short
const postsCount =
posts?.filter((post) => post.post_type !== 3).length || 0;
const minWordCount = isTesting
? true
: wordCount > MIN_BOTTOM_MAP_WORD_COUNT;
return (
this.siteSettings.show_bottom_topic_map &&
!loading &&
postsCount > MIN_POSTS_COUNT
postsCount > MIN_POSTS_COUNT &&
minWordCount
);
}

View File

@ -21,7 +21,6 @@ describe "Topic Map", type: :system do
topic_page.visit_topic(topic)
expect(topic_page).to have_topic_map
2.times { Fabricate(:post, topic: topic, created_at: 1.day.ago, like_count: 1) }
page.refresh
expect(topic_page).to have_topic_map
expect(topic_map).to have_no_users
@ -32,6 +31,7 @@ describe "Topic Map", type: :system do
# bottom map, avatars details with post counts
expect(topic_map).to have_no_bottom_map
2.times { Fabricate(:post, topic: topic, created_at: 1.day.ago, like_count: 1) }
Fabricate(:post, topic: topic, created_at: 2.day.ago)
Fabricate(:post, topic: topic, created_at: 1.day.ago, like_count: 3)
page.refresh