Skip to content

Remove messages deleted while a room page was disconnected - #414

Open
namespaceMarcello wants to merge 1 commit into
basecamp:mainfrom
namespaceMarcello:remove-messages-deleted-while-away
Open

namespaceMarcello wants to merge 1 commit into
basecamp:mainfrom
namespaceMarcello:remove-messages-deleted-while-away

Conversation

@namespaceMarcello

Copy link
Copy Markdown
Contributor

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, which RemoveBannedContentJob runs 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 build of 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. On main (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#destroy and User#remove_banned_content destroy the row and call Message#broadcast_remove, which only reaches pages connected at that moment. When a page reconnects, refresh_room_controller.js asks Rooms::RefreshesController#show for what changed since its 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 sends shown, the ids of the messages the page shows (its message targets), comma-separated. That's at most about 320 ids, since the paginator trims the list past MAX_MESSAGES and its leeway.
  • Rooms::RefreshesController#show takes the ids among those that aren't messages of the room, and rooms/refreshes/show.turbo_stream.erb answers a remove for each, as messages/destroy does for a deletion seen live. An id from another room counts as gone too, so the answer doesn't tell whether it exists elsewhere.
  • A page still running the old JavaScript sends no shown and 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:

  • a message deleted meanwhile is gone once the page reconnects, and one still in the room stays;
  • the messages of someone banned meanwhile, removed as RemoveBannedContentJob does, are gone once the page reconnects.

Both fail without this change, at a removed message still shown.

Two controller tests: the refresh answers a remove for each id shown that's gone, an id from another room included, and none for one still in the room; and no remove for a request without shown, 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.rb and the 32 system tests pass locally (Docker, headless Chrome).

Risk

  • Each refresh's URL carries the ids: under 3 KB with 320 messages and 8-digit ids. The server runs one more query, by primary key within the room.
  • What the page shows and the room no longer has is removed; nothing else is.

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 changes Rooms::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.

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A message deleted while a room page is disconnected stays on it after it reconnects

2 participants