A platform for community discussion. Free, open, simple.
FIX: Create post notices only for public posts (#8708)
Dan Ungureanuc2d051315d0e
diff --git a/lib/post_creator.rb b/lib/post_creator.rbindex d914a735831..78998f8382b 100644--- a/lib/post_creator.rb+++ b/lib/post_creator.rb@@ -550,8 +550,12 @@ class PostCreatordef create_post_noticereturn if @opts[:import_mode] || @user.anonymous? || @user.bot? || @user.staged+ return if @post.topic.archetype != Archetype.default- last_post_time = Post.where(user_id: @user.id)+ last_post_time = Post+ .joins("JOIN topics ON topics.id = posts.topic_id")+ .where(user_id: @user.id)+ .where(topics: { archetype: Archetype.default }).order(created_at: :desc).limit(1).pluck(:created_at)diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rbindex dfcf8e0c81e..0955434daac 100644--- a/spec/components/post_creator_spec.rb+++ b/spec/components/post_creator_spec.rb@@ -1357,6 +1357,9 @@ describe PostCreator dofab!(:anonymous) { Fabricate(:anonymous) }it "generates post notices for new users" do+ post = PostCreator.create!(user, title: "private message topic", raw: "private message post", archetype: Archetype.private_message, target_usernames: user.username)+ expect(post.custom_fields[Post::NOTICE_TYPE]).to eq(nil)+post = PostCreator.create!(user, title: "one of my first topics", raw: "one of my first posts")expect(post.custom_fields[Post::NOTICE_TYPE]).to eq(Post.notices[:new_user])@@ -1368,6 +1371,9 @@ describe PostCreator doSiteSetting.returning_users_days = 30old_post = Fabricate(:post, user: user, created_at: 31.days.ago)+ post = PostCreator.create!(user, title: "private message topic", raw: "private message post", archetype: Archetype.private_message, target_usernames: user.username)+ expect(post.custom_fields[Post::NOTICE_TYPE]).to eq(nil)+post = PostCreator.create!(user, title: "this is a returning topic", raw: "this is a post")expect(post.custom_fields[Post::NOTICE_TYPE]).to eq(Post.notices[:returning_user])expect(post.custom_fields[Post::NOTICE_ARGS]).to eq(old_post.created_at.iso8601)