Skip to content

feat(nomad devices): store remote messages into db (part 13) [WPB-23813]#3923

Merged
MohamadJaara merged 12 commits intodevelopfrom
nomad-devices/feat/store-remote-messages-into-DB
Mar 9, 2026
Merged

feat(nomad devices): store remote messages into db (part 13) [WPB-23813]#3923
MohamadJaara merged 12 commits intodevelopfrom
nomad-devices/feat/store-remote-messages-into-DB

Conversation

@MohamadJaara
Copy link
Copy Markdown
Member

@MohamadJaara MohamadJaara commented Mar 3, 2026

https://wearezeta.atlassian.net/browse/WPB-23813


PR Submission Checklist for internal contributors

  • The PR Title
    - [x] conforms to the style of semantic commits messages¹ supported in Wire's Github Workflow²
    - [x] contains a reference JIRA issue number like SQPIT-764
    - [x] answers the question:
    If merged, this PR will: ... ³
  • The PR Description
    • is free of optional paragraphs and you have filled the relevant parts to the best of your ability

What's new in this PR?
Issues

  • Nomad (shared) devices need to sync all remote messages from the backend and persist them locally so the conversation history is available on the device.
    Solutions
  • Implemented a three-stage pipeline to fetch, decode, and store remote messages:
    1. FetchSyncNomadAllMessagesUseCase calls NomadDeviceSyncApi.getAllMessages() (GET /all-messages) to retrieve all conversations and their messages.
    2. Decode & MapNomadAllMessagesMapper decodes each message's Base64 protobuf payload (NomadDeviceMessagePayload) and maps it to a SyncableMessagePayloadEntity (Text, Asset, Location, Multipart, or Unsupported).
    3. Batch PersistNomadMessagesDAO.storeMessages() inserts messages into the SQLDelight database in batches (default 200), each batch in its own transaction. Before inserting messages, placeholder User and Conversation rows are created to satisfy foreign key constraints. Conversations are marked incomplete_metadata=1 to be enriched later by a separate metadata sync.
  • Key behaviors:
    • Idempotent — uses INSERT OR IGNORE so re-syncing is safe.
    • Resilient — invalid Base64/protobuf payloads are skipped, not fatal. Assets missing required fields fall back to Unknown content type.
    • Per-batch transactions — one failing batch doesn't roll back others.
    • Timestamp heuristic — values < 10B treated as epoch seconds, otherwise milliseconds.
Nomad Backend                SyncNomadAllMessagesUseCase              SQLDelight DB
     │                                  │                                  │
     │  GET /all-messages               │                                  │
     │◄─────────────────────────────────│                                  │
     │                                  │                                  │
     │  NomadAllMessagesResponse        │                                  │
     │  (JSON: conversations[]          │                                  │
     │    → messages[] w/ base64        │                                  │
     │      protobuf payloads)          │                                  │
     │─────────────────────────────────►│                                  │
     │                                  │                                  │
     │                    NomadAllMessagesMapper                            │
     │                    ┌────────────────────────┐                       │
     │                    │ Base64 → bytes          │                       │
     │                    │ → protobuf decode       │                       │
     │                    │ → SyncableMessagePayload│                       │
     │                    │   Entity (5 types)      │                       │
     │                    └────────────────────────┘                       │
     │                                  │                                  │
     │                         NomadMessagesDAO                            │
     │                    (batched, 200 per txn)                           │
     │                                  │  1. INSERT placeholder Users     │
     │                                  │  2. INSERT placeholder Convos    │
     │                                  │  3. INSERT Messages + Content    │
     │                                  │─────────────────────────────────►│

Content Type Mapping

Protobuf Entity DB Table
NomadDeviceText Text MessageTextContent + MessageMention
NomadDeviceAsset Asset MessageAssetContent
NomadDeviceLocation Location MessageConversationLocationContent
NomadDeviceMultipart Multipart MessageTextContent + MessageMention + MessageAttachments
null/unknown Unsupported MessageUnknownContent

Key Behaviors

  • Batched transactions — messages are inserted in chunks of 200; each batch is an independent transaction (one failing batch doesn't roll back others)
  • Placeholder rows — minimal User and Conversation rows are created before message insertion; conversations are marked incomplete_metadata=1 for later enrichment
  • IdempotentINSERT OR IGNORE on messages, so re-syncing the same data is safe
  • Resilient — invalid Base64/protobuf payloads are skipped, not fatal; assets missing required fields fall back to Unknown content type

@MohamadJaara MohamadJaara force-pushed the nomad-devices/feat/store-remote-messages-into-DB branch from ab986e8 to 260a979 Compare March 3, 2026 14:31
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 3, 2026

Test Results

0 tests   - 4 534   0 ✅  - 4 417   0s ⏱️ - 2m 55s
0 suites  -   753   0 💤  -   117 
0 files    -   753   0 ❌ ±    0 

Results for commit 7097e27. ± Comparison against base commit ad5ddcc.

♻️ This comment has been updated with latest results.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 75.63739% with 86 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.79%. Comparing base (ad5ddcc) to head (7097e27).
⚠️ Report is 31 commits behind head on develop.

Files with missing lines Patch % Lines
.../kalium/persistence/dao/backup/NomadMessagesDAO.kt 70.98% 31 Missing and 16 partials ⚠️
.../wire/kalium/nomaddevice/NomadAllMessagesMapper.kt 77.53% 20 Missing and 11 partials ⚠️
.../kalium/nomaddevice/SyncNomadAllMessagesUseCase.kt 82.97% 8 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3923      +/-   ##
===========================================
+ Coverage    59.22%   59.79%   +0.57%     
===========================================
  Files         1962     1965       +3     
  Lines        62891    63255     +364     
  Branches      6834     6877      +43     
===========================================
+ Hits         37249    37826     +577     
+ Misses       22590    22328     -262     
- Partials      3052     3101      +49     
Files with missing lines Coverage Δ
.../wire/kalium/persistence/dao/message/MessageDAO.kt 73.33% <ø> (ø)
.../wire/kalium/persistence/db/UserDatabaseBuilder.kt 77.54% <100.00%> (+1.29%) ⬆️
...maddevice/SyncNomadRemoteBackupChangeLogUseCase.kt 77.77% <ø> (ø)
.../kalium/nomaddevice/SyncNomadAllMessagesUseCase.kt 82.97% <82.97%> (ø)
.../wire/kalium/nomaddevice/NomadAllMessagesMapper.kt 77.53% <77.53%> (ø)
.../kalium/persistence/dao/backup/NomadMessagesDAO.kt 70.98% <70.98%> (ø)

... and 12 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ad5ddcc...7097e27. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 3, 2026

@MohamadJaara MohamadJaara marked this pull request as ready for review March 4, 2026 08:28
@MohamadJaara MohamadJaara enabled auto-merge March 4, 2026 09:05
@MohamadJaara MohamadJaara changed the title feat(nomad devices):store remote messages into db (part 13) [WPB-23813] feat(nomad devices): store remote messages into db (part 13) [WPB-23813] Mar 4, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 9, 2026

@MohamadJaara MohamadJaara added this pull request to the merge queue Mar 9, 2026
Merged via the queue into develop with commit ab1bbc6 Mar 9, 2026
28 of 29 checks passed
@MohamadJaara MohamadJaara deleted the nomad-devices/feat/store-remote-messages-into-DB branch March 9, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants