A platform for community discussion. Free, open, simple.
FIX: `TopicQuery.list_private_messages_unread` ignore notification level
Guo Xiang Tan2ff16b365069
diff --git a/lib/topic_query.rb b/lib/topic_query.rbindex a9ae9786f11..710da62d84e 100644--- a/lib/topic_query.rb+++ b/lib/topic_query.rb@@ -328,7 +328,15 @@ class TopicQuerydef list_private_messages_unread(user)list = private_messages_for(user, :user)- list = list.where("tu.last_read_post_number IS NULL OR tu.last_read_post_number < topics.highest_post_number")++ list = TopicQuery.unread_filter(+ list,+ user.id,+ staff: user.staff?+ )++ first_unread_pm_at = UserStat.where(user_id: user.id).pluck(:first_unread_pm_at).first+ list = list.where("topics.updated_at >= ?", first_unread_pm_at) if first_unread_pm_atcreate_list(:private_messages, {}, list)enddiff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rbindex 349da25a556..3b54f45d465 100644--- a/spec/requests/list_controller_spec.rb+++ b/spec/requests/list_controller_spec.rb@@ -638,26 +638,35 @@ RSpec.describe ListController doendend- describe "private_messages_unread" do- before do- u = Fabricate(:user)- pm = Fabricate(:private_message_topic, user: u)- Fabricate(:post, user: u, topic: pm, post_number: 1)- pm.topic_allowed_users.create!(user: user)+ describe "#private_messages_unread" do+ fab!(:pm_user) { Fabricate(:user) }++ fab!(:pm) do+ Fabricate(:private_message_topic).tap do |t|+ t.allowed_users << pm_user+ create_post(user: pm_user, topic_id: t.id)+ endendit "returns 403 error when the user can't see private message" dosign_in(Fabricate(:user))- get "/topics/private-messages-unread/#{user.username}.json"- expect(response).to be_forbidden+ get "/topics/private-messages-unread/#{pm_user.username}.json"+ expect(response.status).to eq(403)endit "succeeds when the user can see private messages" do- sign_in(user)- get "/topics/private-messages-unread/#{user.username}.json"+ TopicUser.find_by(topic: pm, user: pm_user).update!(+ notification_level: TopicUser.notification_levels[:tracking],+ last_read_post_number: 0,+ )++ sign_in(pm_user)+ get "/topics/private-messages-unread/#{pm_user.username}.json"+expect(response.status).to eq(200)json = response.parsed_bodyexpect(json["topic_list"]["topics"].size).to eq(1)+ expect(json["topic_list"]["topics"][0]["id"]).to eq(pm.id)endend