Skip to content

[inbox] add module - #256

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

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.

RetriggerConfidence Score: 5/5

The PR appears safe to merge because the previously reported migration failure has been corrected and no blocking failure remains.

Summary

The PR adds durable inbox synchronization, retrieval, attachment handling, and retention cleanup for encrypted incoming messages.

  • Adds mobile submission and third-party listing, refresh, and attachment endpoints.
  • Adds inbox and attachment persistence with ownership relationships and duplicate protection.
  • Adds worker-based retention cleanup and corresponding configuration.
  • Updates the client dependency, OpenAPI output, examples, and message conversion.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
    Mobile[Android device] -->|Encrypted inbox upload| API[Mobile inbox endpoint]
    Consumer[Third-party client] -->|List / refresh / attachment read| API
    API --> Service[Inbox service]
    Service --> DB[(inbox and inbox_attachments)]
    Worker[Retention worker] -->|Delete expired records| DB
Loading

Reviews (29) · Last reviewed commit: "[inbox] add module"

@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 Outdated
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 3 times, most recently 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
@capcom6
capcom6 force-pushed the incoming/add-module branch from a4fbcf8 to 30a4b34 Compare August 6, 2026 07:54
@capcom6 capcom6 added the ready label Aug 6, 2026
@capcom6
capcom6 force-pushed the incoming/add-module branch from 30a4b34 to fef19c9 Compare August 8, 2026 01:23
@github-actions github-actions Bot removed the ready label Aug 8, 2026
@capcom6
capcom6 force-pushed the incoming/add-module branch 6 times, most recently from d2e643f to 6ccbc88 Compare August 14, 2026 01:18
@capcom6 capcom6 added the ready label Aug 14, 2026
@capcom6
capcom6 force-pushed the incoming/add-module branch from 6ccbc88 to fb84b11 Compare August 18, 2026 00:23
@github-actions github-actions Bot removed the ready label Aug 18, 2026
@capcom6 capcom6 added the ready label Aug 18, 2026
@capcom6
capcom6 force-pushed the incoming/add-module branch from fb84b11 to 76a53a7 Compare August 20, 2026 00:32
@github-actions github-actions Bot removed the ready label Aug 20, 2026
@capcom6 capcom6 added the ready label Aug 20, 2026
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 7 days with no activity.

@github-actions github-actions Bot added the stale label Aug 27, 2026
@capcom6 capcom6 self-assigned this Aug 28, 2026
@capcom6 capcom6 removed the stale label Aug 28, 2026
@capcom6
capcom6 force-pushed the incoming/add-module branch from 796c19b to d435d79 Compare September 2, 2026 00:46
@github-actions github-actions Bot removed the ready label Sep 2, 2026
@capcom6
capcom6 force-pushed the incoming/add-module branch from 95d8496 to 1379dae Compare September 2, 2026 07:10
@capcom6 capcom6 added the ready label Sep 3, 2026
@github-actions github-actions Bot removed the ready label Sep 10, 2026
@capcom6
capcom6 force-pushed the incoming/add-module branch from 59514b1 to d51d790 Compare September 12, 2026 03:58
@capcom6 capcom6 added the ready label Sep 13, 2026
@github-actions github-actions Bot removed the ready label Sep 18, 2026
@capcom6 capcom6 added the ready label Sep 18, 2026
@capcom6
capcom6 force-pushed the incoming/add-module branch from 434c3ed to 9cc6f39 Compare September 21, 2026 05:17
@github-actions github-actions Bot removed the ready label Sep 21, 2026
@capcom6
capcom6 force-pushed the incoming/add-module branch 2 times, most recently from fa16e4f to ca1fa4e Compare September 22, 2026 03:15
@capcom6 capcom6 added the ready label Sep 22, 2026
@capcom6
capcom6 force-pushed the incoming/add-module branch from ca1fa4e to c24ae3d Compare September 23, 2026 02:21
@github-actions github-actions Bot removed the ready label Sep 23, 2026
@capcom6 capcom6 added the deployed The PR is deployed on staging label Sep 23, 2026

This branch has not been deployed

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

Labels

deployed The PR is deployed on staging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant