mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-08 15:50:08 +09:00
Skip the unread notice for members who have caught up
Now that the unread fanout runs in a job, it can run after a member has already opened the room and moved on to another one. Their sidebar would then mark the room unread for a message they have seen. The job now notifies only members who still have the room unread or are in it now. Room#receive marks members who aren't in the room unread, and opening the room clears it, so a member who caught up in the meantime is skipped. When the job runs right away this is the same set of people as before, except members who have hidden the room, whose sidebar doesn't list it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JVFo3Lt9T8M5NR7KxVvsZ2
This commit is contained in:
@@ -58,6 +58,8 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "creating a message broadcasts unread room to each member" do
|
||||
memberships(:david_watercooler).present # the poster is in the room
|
||||
|
||||
@room.users.each do |member|
|
||||
assert_broadcasts UnreadRoomsChannel.stream_name_for(member.id), 1 do
|
||||
perform_enqueued_jobs only: Message::BroadcastUnreadRoomJob do
|
||||
@@ -77,6 +79,20 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_enqueued_with job: Message::BroadcastUnreadRoomJob, args: [ Message.last ]
|
||||
end
|
||||
|
||||
test "the unread fanout skips a member who has opened the room since" do
|
||||
membership = memberships(:jason_watercooler)
|
||||
|
||||
post room_messages_url(@room, format: :turbo_stream), params: { message: { body: "New one", client_message_id: 999 } }
|
||||
assert membership.reload.unread?
|
||||
|
||||
membership.present
|
||||
membership.reload.disconnected
|
||||
|
||||
assert_no_broadcasts UnreadRoomsChannel.stream_name_for(membership.user_id) do
|
||||
perform_enqueued_jobs only: Message::BroadcastUnreadRoomJob
|
||||
end
|
||||
end
|
||||
|
||||
test "creating a message doesn't broadcast unread room to non-members" do
|
||||
outsiders = User.where.not(id: @room.users.map(&:id))
|
||||
assert outsiders.any?, "need someone outside the room for this test to mean anything"
|
||||
|
||||
Reference in New Issue
Block a user