[inbox] ordered batch webhooks#395
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (13)
🚧 Files skipped from review as they are similar to previous changes (13)
WalkthroughIntroduces ChangesWebhook delivery migration and batch emission
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt (1)
100-119: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win"message processed" log now fires even for skipped duplicates.
process()no longer early-returns whensaveAndBuildPayloadreturnsnull(duplicate message); the trailing"ReceiverService::process - message processed"DEBUG log is now always logged, even though the message was actually skipped as a duplicate a few lines earlier (with its own "duplicate message, skipping" log). This makes debug logs misleading when diagnosing duplicate-detection behavior.🩹 Proposed fix
val payload = saveAndBuildPayload(context, message) if (payload != null && triggerWebhooks) { webHooksService.emit(context, payload.first, payload.second) } - logsService.insert( - LogEntry.Priority.DEBUG, - MODULE_NAME, - "ReceiverService::process - message processed", - ) + if (payload != null) { + logsService.insert( + LogEntry.Priority.DEBUG, + MODULE_NAME, + "ReceiverService::process - message processed", + ) + }🤖 Prompt for 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. In `@app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt` around lines 100 - 119, In ReceiverService::process, the trailing "message processed" DEBUG log is being emitted even when saveAndBuildPayload returns null for a duplicate and the message is skipped. Update the control flow so the method returns immediately after the duplicate/null case (or otherwise guards the final log) and only logs "ReceiverService::process - message processed" after a payload has actually been built and any webhook emission path has completed.
🧹 Nitpick comments (3)
app/src/main/java/me/capcom/smsgateway/modules/receiver/events/MessagesExportRequestedEvent.kt (1)
49-51: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate fallback-resolution logic across files.
The exact same
webhookDelivery ?: (triggerWebhooks==false → Disabled) ?: Individualchain is duplicated inMessagesRoutes.kt'sinboxRoutes()handler (per the provided cross-file snippet). Per the PR stack, this same pattern is likely also needed inEventsReceiver.ktandInboxRoutes.kt. Consider extracting this into a shared helper (e.g., a companion function onWebhookDeliveryor an extension) to avoid the two implementations drifting apart during future changes.♻️ Example extraction
// in WebhookDelivery.kt companion object { fun resolve(webhookDelivery: WebhookDelivery?, triggerWebhooks: Boolean?): WebhookDelivery = webhookDelivery ?: (if (triggerWebhooks == false) Disabled else null) ?: Individual }- webhookDelivery = obj.webhookDelivery - ?: (if (obj.triggerWebhooks == false) WebhookDelivery.Disabled else null) - ?: WebhookDelivery.Individual, + webhookDelivery = WebhookDelivery.resolve(obj.webhookDelivery, obj.triggerWebhooks),🤖 Prompt for 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. In `@app/src/main/java/me/capcom/smsgateway/modules/receiver/events/MessagesExportRequestedEvent.kt` around lines 49 - 51, The webhook delivery fallback chain is duplicated across MessagesExportRequestedEvent and the matching handlers in MessagesRoutes/inboxRoutes, with likely copies in EventsReceiver and InboxRoutes, so extract the resolution logic into a shared helper on WebhookDelivery (for example a companion resolver or extension) and update all call sites to use it. Keep the behavior identical to the current chain: prefer the explicit webhookDelivery, otherwise map triggerWebhooks == false to Disabled, otherwise default to Individual, so future changes stay in sync.app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt (1)
27-29: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMinor naming/ordering inconsistency for
SmsDataBatchReceived.For the other pairs, the enum member name mirrors the serialized value's word order (
SmsBatchReceived→"sms:batch:received",MmsBatchReceived→"mms:batch:received",MmsBatchDownloaded→"mms:batch:downloaded"). Here the member isSmsDataBatchReceived(Data before Batch) but the value is"sms:batch:data-received"(Batch before Data). Purely cosmetic since Gson matches on@SerializedName, but worth aligning for readability/consistency.✏️ Optional rename for consistency
- `@SerializedName`("sms:batch:data-received") - SmsDataBatchReceived("sms:batch:data-received"), + `@SerializedName`("sms:batch:data-received") + SmsBatchDataReceived("sms:batch:data-received"),Note: this requires updating all references (e.g.,
ReceiverService.emitBatchWebhooks,SmsDataBatchReceivedPayload) if renamed.🤖 Prompt for 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. In `@app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt` around lines 27 - 29, The `SmsDataBatchReceived` enum entry in `WebHookEvent` has a naming/ordering mismatch with the other webhook event constants. Rename the enum member to match the serialized word order used by the other entries, and update any references such as `ReceiverService.emitBatchWebhooks` and `SmsDataBatchReceivedPayload` if you choose to rename it. Keep the `@SerializedName("sms:batch:data-received")` mapping unchanged so Gson behavior stays the same.app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt (1)
197-246: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTwo parallel
whenmappings must stay in sync; second one silently drops on mismatch.
eventType -> batchEventlogs a WARN for unsupported types, but the secondwhen (batchEvent)that builds the actual payload has an unreachableelse -> return@forEachIndexedwith no logging. If a new batchable event is ever added to the first mapping without a matching branch in the second, its payloads will be silently dropped instead of surfacing a WARN like the first mapping does. Consider consolidating into a single mapping (e.g., a function/map keyed byWebHookEventreturning both the batch event and a(List<Any>) -> Anyconstructor) or at least add the same WARN logging to the secondelsebranch for symmetry.🤖 Prompt for 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. In `@app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt` around lines 197 - 246, The batching logic in ReceiverService::emitBatchWebhooks has two separate when mappings that can drift apart, and the second one currently drops unmatched batch events silently. Update the payload construction path so it stays in sync with the eventType -> batchEvent mapping, either by consolidating both into one mapping/helper or by adding WARN logging in the batchEvent when else branch before returning. Keep the same unique symbols (emitBatchWebhooks, WebHookEvent, webHooksService.emit, logsService.insert) to ensure any future new batchable event surfaces an explicit warning instead of disappearing.
🤖 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 `@app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt`:
- Around line 76-90: In ReceiverService.process, Batch mode currently saves the
entire messages window before any webhook job is emitted, which can permanently
skip remaining webhooks if the process stops mid-flight. Refactor the Batch
branch to process smaller chunks sequentially so each chunk is saved and emitted
before moving to the next, using the existing saveAndBuildPayload and
emitBatchWebhooks flow to limit the blast radius.
---
Outside diff comments:
In `@app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt`:
- Around line 100-119: In ReceiverService::process, the trailing "message
processed" DEBUG log is being emitted even when saveAndBuildPayload returns null
for a duplicate and the message is skipped. Update the control flow so the
method returns immediately after the duplicate/null case (or otherwise guards
the final log) and only logs "ReceiverService::process - message processed"
after a payload has actually been built and any webhook emission path has
completed.
---
Nitpick comments:
In
`@app/src/main/java/me/capcom/smsgateway/modules/receiver/events/MessagesExportRequestedEvent.kt`:
- Around line 49-51: The webhook delivery fallback chain is duplicated across
MessagesExportRequestedEvent and the matching handlers in
MessagesRoutes/inboxRoutes, with likely copies in EventsReceiver and
InboxRoutes, so extract the resolution logic into a shared helper on
WebhookDelivery (for example a companion resolver or extension) and update all
call sites to use it. Keep the behavior identical to the current chain: prefer
the explicit webhookDelivery, otherwise map triggerWebhooks == false to
Disabled, otherwise default to Individual, so future changes stay in sync.
In `@app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt`:
- Around line 197-246: The batching logic in ReceiverService::emitBatchWebhooks
has two separate when mappings that can drift apart, and the second one
currently drops unmatched batch events silently. Update the payload construction
path so it stays in sync with the eventType -> batchEvent mapping, either by
consolidating both into one mapping/helper or by adding WARN logging in the
batchEvent when else branch before returning. Keep the same unique symbols
(emitBatchWebhooks, WebHookEvent, webHooksService.emit, logsService.insert) to
ensure any future new batchable event surfaces an explicit warning instead of
disappearing.
In
`@app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt`:
- Around line 27-29: The `SmsDataBatchReceived` enum entry in `WebHookEvent` has
a naming/ordering mismatch with the other webhook event constants. Rename the
enum member to match the serialized word order used by the other entries, and
update any references such as `ReceiverService.emitBatchWebhooks` and
`SmsDataBatchReceivedPayload` if you choose to rename it. Keep the
`@SerializedName("sms:batch:data-received")` mapping unchanged so Gson behavior
stays the same.
🪄 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
Run ID: 8e95f3d5-5da1-4b06-a406-0d830f3c4325
📒 Files selected for processing (13)
app/src/main/java/me/capcom/smsgateway/domain/WebhookDelivery.ktapp/src/main/java/me/capcom/smsgateway/modules/localserver/domain/InboxRefreshRequest.ktapp/src/main/java/me/capcom/smsgateway/modules/localserver/routes/InboxRoutes.ktapp/src/main/java/me/capcom/smsgateway/modules/localserver/routes/MessagesRoutes.ktapp/src/main/java/me/capcom/smsgateway/modules/receiver/EventsReceiver.ktapp/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.ktapp/src/main/java/me/capcom/smsgateway/modules/receiver/events/MessagesExportRequestedEvent.ktapp/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.ktapp/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/BatchEventPayload.ktapp/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/MmsBatchDownloadedPayload.ktapp/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/MmsBatchReceivedPayload.ktapp/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsBatchReceivedPayload.ktapp/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsDataBatchReceivedPayload.kt
bdef998 to
85dccf5
Compare
🤖 Pull request artifacts
|
85dccf5 to
3f5aac4
Compare
Summary by CodeRabbit
triggerWebhooksis deprecated).