Repository navigation
Extract ChatDBReader and MessageBuilder from DatabaseHandler - #76
Merged
Merged
Conversation
ChatDBReader owns the SQLite read layer (SQL → row DTOs, attributedBody decoding); MessageBuilder converts DTOs → Message/Person/Group/Attachment with an injectable contactNameResolver. DatabaseHandler keeps polling/WAL orchestration and inbound deferral policy only. Removes the unused MessageSource pass-through seam (protocol + InMemoryMessageSource + convenience init) now that the real chat.db→Message seam has dedicated adapters. Adds MessageBuilderTests covering DTO→entity conversion in isolation (no SQLite or Contacts dependency). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Closes #67
Summary
Deepens
DatabaseHandlerby splitting its chat.db→Messageresponsibilities into two focused adapters:ChatDBReader— owns the read-only SQLite handle and all SQL. Returns plain row DTOs (MessageRow,GroupParticipantRow,AttachmentRow). Resolves message text from either thetextcolumn or the Ventura-eraattributedBodyblob. NoMessage, routing, or contact knowledge.MessageBuilder— converts DTOs →Message/Person/Group/Attachment. Owns isFromMe sender/recipient branching,mailto:stripping, and group/attachment assembly.contactNameResolveris injected, so it is unit-testable without the Contacts XPC service or a live database.DatabaseHandler— now polling/WAL orchestration plus the inbound deferral policy (deferring rows once while Messages backfillshandle_id) only.MessageSource seam removed
Per the acceptance criterion to evaluate whether the
MessageSourceseam earns its keep: it was a pass-through (onMessage: ((Message) -> Void)?) whose only consumer was an unusedDatabaseHandlerconvenience init. WithChatDBReader+MessageBuildernow the real seam,MessageSource,InMemoryMessageSource, the convenience init, andMessageSourceTestsare removed.Test plan
bash ./.github/scripts/test-macos.sh— 114 tests, all passDatabaseHandlerTest(poll/defer/self-chat/outgoing/group edge cases) passes unchanged against the refactorMessageBuilderTests(11 tests) cover DTO→entity conversion in isolation: incoming/outgoing sender resolution,mailto:stripping, group recipient, contact-name resolver, group GUID fallback, attachment mappingAcceptance criteria
ChatDBReaderhas noMessage/ routing knowledgeMessageBuildertested in isolation (no SQLite/Contacts)DatabaseHandlerTeststill passesMessageSourceseam → removed (did not earn its keep)🤖 Generated with Claude Code