mirror of
https://github.com/discourse/discourse.git
synced 2025-06-07 17:34:39 +08:00
UX: reduce bottom topic map threshold, with protections (#29665)
This commit is contained in:
@ -28,7 +28,7 @@ const MIN_LIKES_COUNT = 5;
|
|||||||
const MIN_PARTICIPANTS_COUNT = 5;
|
const MIN_PARTICIPANTS_COUNT = 5;
|
||||||
const MIN_USERS_COUNT_FOR_AVATARS = 2;
|
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 {
|
export default class TopicMapSummary extends Component {
|
||||||
@service site;
|
@service site;
|
||||||
|
@ -34,6 +34,7 @@ import Composer from "discourse/models/composer";
|
|||||||
import Post from "discourse/models/post";
|
import Post from "discourse/models/post";
|
||||||
import Topic from "discourse/models/topic";
|
import Topic from "discourse/models/topic";
|
||||||
import TopicTimer from "discourse/models/topic-timer";
|
import TopicTimer from "discourse/models/topic-timer";
|
||||||
|
import { isTesting } from "discourse-common/config/environment";
|
||||||
import discourseLater from "discourse-common/lib/later";
|
import discourseLater from "discourse-common/lib/later";
|
||||||
import { deepMerge } from "discourse-common/lib/object";
|
import { deepMerge } from "discourse-common/lib/object";
|
||||||
import discourseComputed, { bind } from "discourse-common/utils/decorators";
|
import discourseComputed, { bind } from "discourse-common/utils/decorators";
|
||||||
@ -41,6 +42,7 @@ import I18n from "discourse-i18n";
|
|||||||
let customPostMessageCallbacks = {};
|
let customPostMessageCallbacks = {};
|
||||||
|
|
||||||
const RETRIES_ON_RATE_LIMIT = 4;
|
const RETRIES_ON_RATE_LIMIT = 4;
|
||||||
|
const MIN_BOTTOM_MAP_WORD_COUNT = 200;
|
||||||
|
|
||||||
export function resetCustomPostMessageCallbacks() {
|
export function resetCustomPostMessageCallbacks() {
|
||||||
customPostMessageCallbacks = {};
|
customPostMessageCallbacks = {};
|
||||||
@ -233,12 +235,25 @@ export default class TopicController extends Controller.extend(
|
|||||||
return Category.findById(categoryId)?.minimumRequiredTags || 0;
|
return Category.findById(categoryId)?.minimumRequiredTags || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@discourseComputed("model.posts_count", "model.postStream.loadingFilter")
|
@discourseComputed(
|
||||||
showBottomTopicMap(postsCount, loading) {
|
"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 (
|
return (
|
||||||
this.siteSettings.show_bottom_topic_map &&
|
this.siteSettings.show_bottom_topic_map &&
|
||||||
!loading &&
|
!loading &&
|
||||||
postsCount > MIN_POSTS_COUNT
|
postsCount > MIN_POSTS_COUNT &&
|
||||||
|
minWordCount
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ describe "Topic Map", type: :system do
|
|||||||
topic_page.visit_topic(topic)
|
topic_page.visit_topic(topic)
|
||||||
|
|
||||||
expect(topic_page).to have_topic_map
|
expect(topic_page).to have_topic_map
|
||||||
2.times { Fabricate(:post, topic: topic, created_at: 1.day.ago, like_count: 1) }
|
|
||||||
page.refresh
|
page.refresh
|
||||||
expect(topic_page).to have_topic_map
|
expect(topic_page).to have_topic_map
|
||||||
expect(topic_map).to have_no_users
|
expect(topic_map).to have_no_users
|
||||||
@ -32,6 +31,7 @@ describe "Topic Map", type: :system do
|
|||||||
# bottom map, avatars details with post counts
|
# bottom map, avatars details with post counts
|
||||||
expect(topic_map).to have_no_bottom_map
|
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: 2.day.ago)
|
||||||
Fabricate(:post, topic: topic, created_at: 1.day.ago, like_count: 3)
|
Fabricate(:post, topic: topic, created_at: 1.day.ago, like_count: 3)
|
||||||
page.refresh
|
page.refresh
|
||||||
|
Reference in New Issue
Block a user