DEV: don't mark messages as unread when they are closed (#35451)

In f71e9aad60 we've added a new user
preference to let users control whether they want to silence "close"
notifications.

This was also working for "messages", but was missing a spec.

⚠️ This is a spec-only change, no behavior was changed ⚠️

Internal ref - t/159399
This commit is contained in:
Régis Hanol
2025-10-16 19:21:32 +02:00
committed by GitHub
parent 5dd149079b
commit da57542a21
@@ -27,6 +27,52 @@ RSpec.describe TopicStatusUpdater do
expect(tu.last_read_post_number).to eq(2)
end
it "respects topics_unread_when_closed preference for private messages" do
user_wants_unread = Fabricate(:user)
user_wants_unread.user_option.update!(topics_unread_when_closed: true)
user_wants_read = Fabricate(:user)
user_wants_read.user_option.update!(topics_unread_when_closed: false)
post =
PostCreator.create(
user,
raw: "this is a private message",
title: "private message title",
archetype: Archetype.private_message,
target_usernames: [user_wants_unread.username, user_wants_read.username],
)
TopicUser.update_last_read(user_wants_unread, post.topic.id, 1, 1, 0)
TopicUser.update_last_read(user_wants_read, post.topic.id, 1, 1, 0)
PostTiming.create!(
topic_id: post.topic.id,
post_number: 1,
user_id: user_wants_unread.id,
msecs: 1000,
)
PostTiming.create!(
topic_id: post.topic.id,
post_number: 1,
user_id: user_wants_read.id,
msecs: 1000,
)
TopicStatusUpdater.new(post.topic, admin).update!("closed", true)
# Should have 2 posts (original + close action)
expect(post.topic.posts.count).to eq(2)
# User with topics_unread_when_closed enabled should NOT have read the close action
tu_wants_unread = TopicUser.find_by(user_id: user_wants_unread.id, topic_id: post.topic.id)
expect(tu_wants_unread.last_read_post_number).to eq(1)
# User with topics_unread_when_closed disabled SHOULD have read the close action
tu_wants_read = TopicUser.find_by(user_id: user_wants_read.id, topic_id: post.topic.id)
expect(tu_wants_read.last_read_post_number).to eq(2)
end
it "adds an autoclosed message" do
topic = create_topic
topic.set_or_create_timer(TopicTimer.types[:close], "10")