Repository navigation
Conversation
A system message is a message: post_system_message! bumps messages_count and moves last_message like a human one, and the inbox relies on that, so "Your ride was cancelled" still surfaces a thread nobody typed in. Ops walls, moderation lists and analytics ask the opposite question: did a person actually say anything here? Hosts were answering it with their own EXISTS subquery and their own "last human message" query (CarHey's madmin chats wall, with a PostgreSQL-only DISTINCT ON). Additive, nothing changes by default: - Chats::Message.conversational: kind "text" and not deleted (a captionless photo counts, a tombstone does not) - Chats::Conversation.with_conversation / .without_conversation: one correlated EXISTS / NOT EXISTS built from Message.conversational through Arel, so they compose with inbox_for, about, unread_by and never multiply rows - Conversation#last_conversational_message, and its one-query batch twin Chats::Message.last_conversational_in(conversations), ranked with ROW_NUMBER like Chats::Inbox's stacks (PostgreSQL, MySQL 8, SQLite); a relation, so a host can narrow the columns before index_by README gains "Real conversations vs system-only threads" under the data model plus the API reference lines; CHANGELOG 0.3.3 (unreleased). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T5EyMJjNWMPADZwjXBdiiZ
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.
A system message is a message:
post_system_message!bumpsmessages_countand moveslast_messagelike a human one. The inbox relies on that, so "Your ride was cancelled" still surfaces a thread nobody typed in. Ops walls, moderation lists and analytics ask the opposite question: did a person actually say anything here? CarHey's madmin chats wall answered it with its ownEXISTSsubquery and a PostgreSQL-onlyDISTINCT ON"last human message" query. The primitive belongs in the gem.Everything is additive. The inbox, unread counts,
messages_countandlast_messagebehave exactly as before.Chats::Message.conversational: kindtextand not deleted. A captionless photo counts, a tombstone does not.Chats::Conversation.with_conversation/.without_conversation: one correlatedEXISTS/NOT EXISTS, built through Arel fromMessage.conversationalso the two definitions cannot drift. They compose withinbox_for,aboutandunread_byand never multiply rows.Conversation#last_conversational_message: the newest of those, or nil. It is a query, not the denormalized pointer.Chats::Message.last_conversational_in(conversations): the one-query batch twin for lists, ranked withROW_NUMBERlikeChats::Inbox's stacks. It returns a relation, so a host can narrow the columns beforeindex_by(&:conversation_id). The ranked subquery is built unscoped so a chained.selectnever leaks into it.README gains "Real conversations vs system-only threads" under the data model, plus the API reference lines and the Upgrading note. CHANGELOG has
0.3.3 - unreleased, andChats::VERSIONis 0.3.3. No gem was built or published.Validation, run locally on Ruby 3.4.7:
The new
test/models/chats/conversational_scopes_test.rbhas 15 tests. They cover text vs system vs tombstone vs empty threads in both directions, the exact-complement property, composition withinbox_forandunread_by, a single-query assertion for the scopes and the batch helper, and acreated_attie broken the wayrecent_firstbreaks it.Host follow-up after the bump: CarHey's
Madmin::ChatsDashboardswapsHUMAN_MESSAGE_SQL/real_conversationsforwith_conversation, and its human-message count and last-message queries forMessage.conversationalandlast_conversational_in.馃 Generated with Claude Code
https://claude.ai/code/session_01T5EyMJjNWMPADZwjXBdiiZ