mirror of
https://github.com/discourse/discourse.git
synced 2025-08-17 18:04:11 +08:00
FIX: composer educational limit should use post count (#33650)
The educational posts site setting (`educate_until_posts`) feels buggy, this is because the logic for showing these messages treats topics and replies (posts) as a separate count. If `SiteSetting.educate_until_posts` has a value of 2, the user can write multiple replies to existing topics and see the "Welcome to our community! You are brand new here..." message for the first 2 times then it will not show again. However, once they decide to create a topic they will see the message again which doesn't feel right. The solution is to use a combined count (`user.topic_count` and `user.post_count`) and check against the site setting value. That way we don't double up educational messages for both topics and replies when using composer.
This commit is contained in:
parent
4101ea9f7c
commit
793c55aa58
2 changed files with 7 additions and 10 deletions
|
@ -26,13 +26,8 @@ class ComposerMessagesFinder
|
|||
def check_education_message
|
||||
return if @topic&.private_message?
|
||||
|
||||
if creating_topic?
|
||||
count = @user.created_topic_count
|
||||
education_key = "education.new-topic"
|
||||
else
|
||||
count = @user.post_count
|
||||
education_key = "education.new-reply"
|
||||
end
|
||||
education_key = creating_topic? ? "education.new-topic" : "education.new-reply"
|
||||
count = @user.topic_count + @user.post_count
|
||||
|
||||
if count < SiteSetting.educate_until_posts
|
||||
return(
|
||||
|
|
|
@ -18,7 +18,7 @@ RSpec.describe ComposerMessagesFinder do
|
|||
end
|
||||
|
||||
describe ".check_education_message" do
|
||||
let(:user) { Fabricate.build(:user) }
|
||||
fab!(:user)
|
||||
|
||||
context "when creating topic" do
|
||||
let(:finder) { ComposerMessagesFinder.new(user, composer_action: "createTopic") }
|
||||
|
@ -26,12 +26,14 @@ RSpec.describe ComposerMessagesFinder do
|
|||
before { SiteSetting.educate_until_posts = 10 }
|
||||
|
||||
it "returns a message for a user who has not posted any topics" do
|
||||
user.expects(:created_topic_count).returns(9)
|
||||
user.expects(:post_count).returns(8)
|
||||
user.expects(:topic_count).returns(1)
|
||||
expect(finder.check_education_message).to be_present
|
||||
end
|
||||
|
||||
it "returns no message when the user has posted enough topics" do
|
||||
user.expects(:created_topic_count).returns(10)
|
||||
user.expects(:post_count).returns(8)
|
||||
user.expects(:topic_count).returns(2)
|
||||
expect(finder.check_education_message).to be_blank
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue