Skip to content

[inbox] add module - #256

Open
capcom6 wants to merge 2 commits into
masterfrom
incoming/add-module
Open

[inbox] add module#256
capcom6 wants to merge 2 commits into
masterfrom
incoming/add-module

Conversation

@capcom6

@capcom6 capcom6 commented Jul 25, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Added a secure mobile inbox endpoint to submit encrypted incoming SMS/data SMS/MMS messages, including attachments (single and batched).
    • Added incoming message listing with device/type and date-range filtering plus pagination.
    • Added secure attachment retrieval with ownership checks.
  • Configuration
    • Added configurable incoming-message retention and automated cleanup (cleanup interval and max age).
  • Bug Fixes
    • Prevents duplicate incoming entries.
    • Rejects unencrypted or empty incoming submissions.

Greptile Summary

The PR adds end-to-end inbox support for encrypted incoming messages, attachment retrieval, filtering, retention, and cleanup.

  • Adds authenticated mobile ingestion and third-party inbox APIs.
  • Introduces inbox persistence models, repository and service logic, and MySQL tables.
  • Registers configurable periodic retention 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

Filename Overview
internal/sms-gateway/models/migrations/mysql/20260724000000_create_incoming_tables.sql Creates compatible inbox and attachment tables; the attachment foreign key now correctly targets inbox(id).
internal/sms-gateway/inbox/service.go Implements inbox ingestion, listing, attachment access, refresh requests, and cleanup orchestration.
internal/sms-gateway/inbox/repository.go Adds persistence, filtering, ownership-aware attachment lookup, duplicate handling, and retention deletion.
internal/sms-gateway/handlers/inbox/3rdparty.go Implements scoped inbox listing, refresh, and attachment download endpoints.
internal/sms-gateway/handlers/inbox/mobile.go Adds authenticated mobile submission of encrypted inbox message batches.
internal/worker/tasks/inbox/cleanup.go Adds scheduled cleanup using the configured retention period.

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] --> Service
Loading

Reviews (2): Last reviewed commit: "[inbox] fix migration" | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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.

Changes

Incoming message subsystem

Layer / File(s) Summary
Incoming contracts and storage schema
internal/sms-gateway/modules/incoming/domain.go, errors.go, models.go, internal/sms-gateway/models/migrations/mysql/*
Defines incoming message and attachment types, validation errors, GORM models, migration registration, and MySQL tables with uniqueness, indexes, and cascading foreign keys.
Persistence and service operations
internal/sms-gateway/modules/incoming/repository.go, service.go
Adds transactional single and batch inserts, idempotent batch handling, user-scoped listing, attachment lookup, cleanup, encryption validation, and model mapping.
Mobile inbox ingestion
internal/sms-gateway/handlers/inbox/*, internal/sms-gateway/handlers/mobile.go, internal/sms-gateway/handlers/module.go, api/mobile.http, go.mod
Adds the authenticated mobile inbox endpoint, converts encrypted request batches, maps validation errors, wires the route, documents example requests, and updates the client dependency.
Configuration and gateway wiring
internal/config/*, internal/sms-gateway/modules/incoming/config.go, internal/sms-gateway/app.go
Adds incoming retention settings, converts them to durations, and registers the incoming module in the gateway FX graph.
Periodic cleanup worker
internal/worker/config/*, internal/worker/tasks/incoming/*, internal/worker/tasks/module.go
Adds cleanup interval and maximum-age configuration, implements the periodic cleanup task, and registers it with the worker FX graph.

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
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: introducing the incoming module and related wiring.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between efb7b48 and a9c6b8b.

📒 Files selected for processing (17)
  • internal/config/config.go
  • internal/config/module.go
  • internal/sms-gateway/app.go
  • internal/sms-gateway/models/migrations/mysql/20260724000000_create_incoming_tables.sql
  • internal/sms-gateway/modules/incoming/config.go
  • internal/sms-gateway/modules/incoming/domain.go
  • internal/sms-gateway/modules/incoming/errors.go
  • internal/sms-gateway/modules/incoming/models.go
  • internal/sms-gateway/modules/incoming/module.go
  • internal/sms-gateway/modules/incoming/repository.go
  • internal/sms-gateway/modules/incoming/service.go
  • internal/worker/config/config.go
  • internal/worker/config/module.go
  • internal/worker/tasks/incoming/cleanup.go
  • internal/worker/tasks/incoming/config.go
  • internal/worker/tasks/incoming/module.go
  • internal/worker/tasks/module.go

Comment thread internal/sms-gateway/inbox/repository.go
Comment thread internal/sms-gateway/modules/incoming/service.go Outdated
Comment thread internal/sms-gateway/modules/incoming/service.go Outdated
Comment thread internal/worker/config/config.go Outdated
@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown

🤖 Pull request artifacts

Platform File
🐳 Docker GitHub Container Registry
🍎 Darwin arm64 server_Darwin_arm64.tar.gz
🍎 Darwin x86_64 server_Darwin_x86_64.tar.gz
🐧 Linux arm64 server_Linux_arm64.tar.gz
🐧 Linux i386 server_Linux_i386.tar.gz
🐧 Linux x86_64 server_Linux_x86_64.tar.gz
🪟 Windows arm64 server_Windows_arm64.zip
🪟 Windows i386 server_Windows_i386.zip
🪟 Windows x86_64 server_Windows_x86_64.zip

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 576c883 and d5fc870.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • api/mobile.http
  • go.mod
  • internal/sms-gateway/handlers/inbox/mobile.go
  • internal/sms-gateway/handlers/mobile.go
  • internal/sms-gateway/handlers/module.go

Comment thread api/mobile.http
@capcom6
capcom6 force-pushed the incoming/add-module branch 6 times, most recently from f6b3797 to 9a120db Compare August 3, 2026 04:08
@capcom6 capcom6 changed the title [incoming] add module [inbox] add module Aug 4, 2026
@capcom6
capcom6 force-pushed the incoming/add-module branch 2 times, most recently from 793956b to 00e72d3 Compare August 4, 2026 11:45
@capcom6
capcom6 force-pushed the incoming/add-module branch from 00e72d3 to a715aad Compare August 5, 2026 01:00
@capcom6
capcom6 marked this pull request as ready for review August 5, 2026 11:24
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.

1 participant