Repository navigation
Remove messages deleted while a room page was disconnected - #414
Open
namespaceMarcello wants to merge 1 commit into
Open
namespaceMarcello wants to merge 1 commit into
namespaceMarcello wants to merge 1 commit into
Conversation
A page that reconnects asks for what changed since its last load, and gets the messages created and updated since then. One deleted meanwhile, by its author, an administrator or a ban, no longer exists, so the page kept showing it until it was reloaded. The refresh now sends the ids of the messages the page shows, and removes those that are no longer in the room. Fixes basecamp#404. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approved
The focused, room-scoped reconciliation preserves compatibility and has targeted regression coverage, with no blocking issues identified in static review.
No open issues 🎉
What changed in this PR
Fixes #404 by reconciling displayed messages when a room refreshes after reconnecting, clearing deletions missed while disconnected, including content removed after a ban.
Changes:
- Sends displayed message IDs with refresh requests.
- Removes IDs no longer present in the room while preserving older-client behavior.
- Adds controller and system coverage for missed deletions and ban cleanup.
[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto reengage.
| File | Description |
|---|---|
test/system/messages_removed_while_away_test.rb |
Tests reconnect cleanup after deletions and bans. |
test/controllers/rooms/refreshes_controller_test.rb |
Tests room-scoped removals and older-client compatibility. |
app/views/rooms/refreshes/show.turbo_stream.erb |
Renders removal streams for missing messages. |
app/javascript/controllers/refresh_room_controller.js |
Includes displayed message IDs in refresh requests. |
app/controllers/rooms/refreshes_controller.rb |
Identifies displayed IDs absent from the room. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #404. When a room page loses its cable connection (a laptop asleep, a dropped network) and a message in the room is deleted meanwhile, the page keeps showing it after it reconnects, until the room is reloaded.
The same goes for everything a ban removes.
User#remove_banned_content, whichRemoveBannedContentJobruns after a ban, destroys each message of the banned user and broadcasts its removal, and that reaches only the pages connected at that moment. So spam or abuse removed by banning its author stays on the screen of everyone who was offline then.With this PR, the refresh a page makes after reconnecting also removes the messages it shows that are no longer in the room.
Measured in Chrome (headless, Selenium) against the production image (
docker buildof each commit,DISABLE_SSL=true, Docker on a laptop), one run each. A member's room page has its cable blocked and its connection dropped while an administrator deletes a message and bans another member through the app's own requests; then the page reconnects. Onmain(59d2164) it still shows 13 messages that are no longer in the database, the deleted one and 12 of the banned member's, after the refresh has brought an edit made meanwhile. With this PR it shows none of them, and the same 27 messages as the administrator's page, which stayed connected.Why it happens
MessagesController#destroyandUser#remove_banned_contentdestroy the row and callMessage#broadcast_remove, which only reaches pages connected at that moment. When a page reconnects,refresh_room_controller.jsasksRooms::RefreshesController#showfor what changedsinceits last load, and gets the messages created and updated since then. A deleted message no longer exists, so nothing in the refresh tells the page to remove it.The change
refresh_room_controller.js: the refresh sendsshown, the ids of the messages the page shows (itsmessagetargets), comma-separated. That's at most about 320 ids, since the paginator trims the list pastMAX_MESSAGESand its leeway.Rooms::RefreshesController#showtakes the ids among those that aren't messages of the room, androoms/refreshes/show.turbo_stream.erbanswers aremovefor each, asmessages/destroydoes for a deletion seen live. An id from another room counts as gone too, so the answer doesn't tell whether it exists elsewhere.shownand gets no removals, as before.#404 mentions other ways, such as a record of deleted messages or reloading the list after reconnecting. This one needs no schema change and leaves the page's scroll position, pagination and pending messages as they are.
Checks
New system tests in
test/system/messages_removed_while_away_test.rb, with the page's cable connection blocked and dropped as in #404:RemoveBannedContentJobdoes, are gone once the page reconnects.Both fail without this change, at a removed message still shown.
Two controller tests: the refresh answers a
removefor each id shown that's gone, an id from another room included, and none for one still in the room; and noremovefor a request withoutshown, as from a page running the old JavaScript.Each piece was broken on its own to see a test fail: the page not sending
shown, the server ignoring it, the removals not rendered, the lookup not limited to the room.The full unit suite (651), rubocop, herb, brakeman,
bench/test_http_client.rband the 32 system tests pass locally (Docker, headless Chrome).Risk
Revert
Revert the commit: a page goes back to keeping messages deleted while it was disconnected until it's reloaded.
#358 and #405 change
refresh_room_controller.js, and #369 changesRooms::RefreshesController#show, its view and its test, none of them in the same lines: git merges each with this one without conflicts, and with #369 merged the refresh controller tests pass.Written by Claude Code (AI assistant) on behalf of @namespaceMarcello, who directs this work.