[inbox] add module - #256
Conversation
📝 WalkthroughWalkthroughAdds an incoming SMS/MMS module with encrypted batch ingestion, persistence, filtered retrieval, attachment access, database migrations, mobile routing, configurable retention, gateway wiring, and a periodic cleanup worker. ChangesIncoming message subsystem
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant MobileClient
participant MobileInboxController
participant IncomingService
participant IncomingRepository
participant MySQL
MobileClient->>MobileInboxController: POST encrypted inbox batch
MobileInboxController->>IncomingService: Convert and validate messages
IncomingService->>IncomingRepository: InsertBatch
IncomingRepository->>MySQL: Persist messages and attachments
MySQL-->>IncomingRepository: Return persistence result
IncomingRepository-->>IncomingService: Complete batch insertion
IncomingService-->>MobileInboxController: Return result
MobileInboxController-->>MobileClient: Return HTTP response
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@internal/sms-gateway/models/migrations/mysql/20260724000000_create_incoming_tables.sql`:
- Around line 3-20: Align the incoming-message soft-delete model with its
queries and retention cleanup: embed the deleted-at field in
IncomingMessageModel, add incoming_messages.deleted_at with an index covering
the soft-delete predicates in the migration, and update Cleanup to use
Unscoped().Delete so expired parent messages and incoming_attachments are
physically removed. Apply the schema change in
internal/sms-gateway/models/migrations/mysql/20260724000000_create_incoming_tables.sql
and the purge change in internal/sms-gateway/modules/incoming/repository.go; the
model change belongs in IncomingMessageModel.
In `@internal/sms-gateway/modules/incoming/repository.go`:
- Around line 53-66: Update the message insertion loop in InsertBatch to inspect
the Create result’s RowsAffected value; only assign attachment MessageID values
and call tx.Create for attachments when a new message was inserted. Skip
attachment processing for conflict-skipped messages while preserving existing
error handling.
In `@internal/sms-gateway/modules/incoming/service.go`:
- Around line 59-70: Update the message construction in the incoming service to
preserve the source timestamp by assigning MessageInput.CreatedAt to
TimedModel.CreatedAt instead of forcing a zero time. Leave UpdatedAt behavior
unchanged and ensure persisted messages retain their original chronological and
retention metadata.
- Around line 46-56: Update the attachment conversion in the incoming message
service to propagate AttachmentInput.IsEncrypted into attachmentModel for every
attachment. Ensure the model field is populated alongside PartID, ContentType,
Name, Size, and Data so encrypted status is retained and plaintext attachments
cannot bypass enforcement.
In `@internal/worker/config/config.go`:
- Around line 41-43: Validate IncomingCleanup during configuration loading and
reject configurations where either Interval or MaxAge is less than or equal to
zero. Ensure invalid values from TASKS__INCOMING_CLEANUP__INTERVAL and
TASKS__INCOMING_CLEANUP__MAX_AGE fail before the cleanup settings are accepted.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f9e16dec-80ba-4687-8de9-08590b8fdd94
📒 Files selected for processing (17)
internal/config/config.gointernal/config/module.gointernal/sms-gateway/app.gointernal/sms-gateway/models/migrations/mysql/20260724000000_create_incoming_tables.sqlinternal/sms-gateway/modules/incoming/config.gointernal/sms-gateway/modules/incoming/domain.gointernal/sms-gateway/modules/incoming/errors.gointernal/sms-gateway/modules/incoming/models.gointernal/sms-gateway/modules/incoming/module.gointernal/sms-gateway/modules/incoming/repository.gointernal/sms-gateway/modules/incoming/service.gointernal/worker/config/config.gointernal/worker/config/module.gointernal/worker/tasks/incoming/cleanup.gointernal/worker/tasks/incoming/config.gointernal/worker/tasks/incoming/module.gointernal/worker/tasks/module.go
🤖 Pull request artifacts
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@api/mobile.http`:
- Around line 119-130: Replace the placeholder data values in the MMS attachment
examples with valid Base64 payloads, including both attachment objects
identified by partId 1 and partId 2, while leaving their metadata unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 824d349e-a81f-4fb8-a037-b984bfb75294
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (5)
api/mobile.httpgo.modinternal/sms-gateway/handlers/inbox/mobile.gointernal/sms-gateway/handlers/mobile.gointernal/sms-gateway/handlers/module.go
f6b3797 to
9a120db
Compare
793956b to
00e72d3
Compare
00e72d3 to
a715aad
Compare
Summary by CodeRabbit
Greptile Summary
The PR adds end-to-end inbox support for encrypted incoming messages, attachment retrieval, filtering, retention, and cleanup.
Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains; the previously reported foreign-key target now matches the inbox table and compatible primary-key type used by the models and repository.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart LR Mobile[Mobile device] -->|Encrypted message batch| MobileAPI[Mobile inbox endpoint] MobileAPI --> Service[Inbox service] Service --> DB[(Inbox and attachment tables)] Client[Third-party client] -->|List and download| ThirdPartyAPI[Third-party inbox API] ThirdPartyAPI --> Service Cleanup[Retention cleanup task] --> ServiceReviews (2): Last reviewed commit: "[inbox] fix migration" | Re-trigger Greptile