Skip to content

Comments

[localserver] add support for data messages#235

Merged
capcom6 merged 6 commits intomasterfrom
feature/data-messages
Jun 27, 2025
Merged

[localserver] add support for data messages#235
capcom6 merged 6 commits intomasterfrom
feature/data-messages

Conversation

@capcom6
Copy link
Owner

@capcom6 capcom6 commented Jun 19, 2025

Summary by CodeRabbit

  • New Features

    • Added support for sending and handling both text and data SMS messages, including specifying data payloads and destination ports.
    • Message content is now structured and can be provided as either plain text or data in API requests.
    • Added webhook event and payload support for data SMS reception.
    • Enhanced SMS receiver to process both text and data SMS messages distinctly.
  • Improvements

    • Enhanced validation for message submission to enforce mutually exclusive message types and ensure correct data formatting.
    • Message details display now shows structured message content.
    • Refactored message sending and storage to use a unified repository and richer message content model.
    • Updated SIM selection and sending logic to support new message content types.
    • Extended SMS broadcast receiver to listen for data SMS on a specific port.
    • Improved message state synchronization and error handling in message processing.
  • Database Migration

    • Upgraded database schema to support the new message content structure, with automatic migration for existing messages.

@coderabbitai
Copy link

coderabbitai bot commented Jun 19, 2025

Walkthrough

This update refactors message handling to support both text and data SMS types using a new MessageContent abstraction. It modifies the database schema, introduces new domain and data classes, updates message construction and validation logic, and migrates message processing to use a repository-based model. UI and ViewModel logic are also adapted accordingly. Additionally, it extends SMS receiving and webhook event handling to support data SMS messages.

Changes

File(s) Change Summary
.../data/AppDatabase.kt, .../data/Migrations.kt, app/schemas/...AppDatabase/14.json Database version bumped to 14; migration replaces text column with JSON content and adds type column; new schema version 14 defined with updated tables and indexes.
.../entities/Message.kt Introduced MessageType enum; replaced text property with type and content in Message data class.
.../domain/MessageContent.kt Added sealed class MessageContent with Text and Data subclasses for message content modeling.
.../modules/gateway/GatewayService.kt Message construction now wraps content in MessageContent.Text instead of using a raw string.
.../modules/localserver/domain/PostMessageRequest.kt Added DataMessage and TextMessage classes; deprecated message property in favor of structured message types.
.../modules/localserver/routes/MessagesRoutes.kt Enforced exclusive message type validation; refactored to use MessageContent abstraction for message construction; added detailed validation and early returns.
.../modules/messages/MessagesService.kt Refactored to use MessagesRepository for enqueueing and retrieval; migrated to new message content model and updated SIM selection and sending logic; supports sending text and data SMS.
.../modules/messages/data/Message.kt Changed text property to content: MessageContent in Message class.
.../modules/messages/data/SendRequest.kt Changed from data class to open class to allow inheritance.
.../modules/messages/data/StoredSendRequest.kt Introduced new class StoredSendRequest extending SendRequest with additional properties.
.../modules/messages/repositories/MessagesRepository.kt Expanded with JSON (de)serialization, domain-to-entity mapping, state synchronization, and new enqueue logic returning domain models.
.../modules/messages/vm/MessageDetailsViewModel.kt Changed LiveData type from MessageWithRecipients to StoredSendRequest.
.../ui/MessageDetailsFragment.kt Updated UI binding to display message.content.toString() instead of message.text.
docs/api/swagger.json Updated API schema to deprecate message string, add mutually exclusive textMessage and dataMessage fields with validation; added SmsDataReceivedPayload schema and new webhook event type.
AndroidManifest.xml Added intent filter for DATA_SMS_RECEIVED on port 53739 to SMS broadcast receiver.
.../modules/receiver/MessagesReceiver.kt Modified to handle both text and data SMS intents, creating typed InboxMessage.Text or InboxMessage.Data instances.
.../modules/receiver/ReceiverService.kt Extended processing to differentiate SmsReceived and new SmsDataReceived events with Base64-encoded data payloads.
.../modules/receiver/data/InboxMessage.kt Changed InboxMessage from data class to sealed class with Text and Data subclasses, each with specific content properties and updated equality/hashCode.
.../modules/webhooks/domain/WebHookEvent.kt Added new enum constant SmsDataReceived for data SMS webhook events.
.../modules/webhooks/payload/SmsEventPayload.kt Added SmsDataReceived subclass with data SMS payload properties.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant MessagesRoutes
    participant MessagesService
    participant MessagesRepository
    participant AppDatabase

    Client->>MessagesRoutes: POST /messages (with textMessage/dataMessage/message)
    MessagesRoutes->>MessagesRoutes: Validate mutual exclusivity and content
    MessagesRoutes->>MessagesService: enqueueMessage(SendRequest with MessageContent)
    MessagesService->>MessagesRepository: enqueue(SendRequest)
    MessagesRepository->>AppDatabase: Insert MessageWithRecipients (content as JSON)
    MessagesRepository-->>MessagesService: Ack

    loop Periodically
        MessagesService->>MessagesRepository: getPending()
        MessagesRepository->>AppDatabase: Query pending messages
        AppDatabase-->>MessagesRepository: MessageWithRecipients (content as JSON)
        MessagesRepository->>MessagesService: StoredSendRequest
        MessagesService->>MessagesService: sendMessage(StoredSendRequest)
        MessagesService->>MessagesService: sendSMS(StoredSendRequest)
        MessagesService->>AppDatabase: Update state/delivery status
    end
Loading
sequenceDiagram
    participant MessagesRoutes
    participant MessageContent

    MessagesRoutes->>MessageContent: Construct Text or Data subclass based on input
    MessageContent-->>MessagesRoutes: MessageContent instance
    MessagesRoutes->>MessagesService: enqueueMessage(SendRequest with MessageContent)
Loading
sequenceDiagram
    participant UI
    participant MessageDetailsViewModel
    participant MessagesRepository

    UI->>MessageDetailsViewModel: Request message details
    MessageDetailsViewModel->>MessagesRepository: get(id)
    MessagesRepository->>AppDatabase: Query by id
    AppDatabase-->>MessagesRepository: MessageWithRecipients (content as JSON)
    MessagesRepository->>MessageDetailsViewModel: StoredSendRequest
    MessageDetailsViewModel->>UI: LiveData<StoredSendRequest>
    UI->>UI: Display message.content.toString()
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch feature/data-messages

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (4)
app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/PostMessageRequest.kt (1)

6-9: Consider validating port range for DataMessage.

The DataMessage class design is clean, but consider adding validation to ensure the port value is within the valid range (0-65535).

 data class DataMessage(
     val data: String,  // Base64-encoded payload
-    val port: Int,      // Destination port (0-65535)
+    val port: Int      // Destination port (0-65535)
 )

Add validation in the constructor or validation logic:

init {
    require(port in 0..65535) { "Port must be in range 0-65535" }
}
app/src/main/java/me/capcom/smsgateway/data/Migrations.kt (1)

18-86: Ensure migration handles large datasets gracefully.

This migration performs a full table copy which could be slow for large message tables. Consider adding progress logging or chunked processing for production environments with large datasets.

app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/MessagesRoutes.kt (1)

153-157: Remove defensive IllegalStateException.

The IllegalStateException on line 155 is unreachable due to the validation logic above. This creates dead code that could confuse future maintainers.

Consider removing the else branch or replacing with a more descriptive comment:

-                else -> {
-                    // This case should be caught by validation, but just in case
-                    throw IllegalStateException("Unknown message type")
-                }
app/src/main/java/me/capcom/smsgateway/modules/messages/repositories/MessagesRepository.kt (1)

18-18: Consider configuring Gson for robustness.

The default Gson configuration may not handle all edge cases in message content serialization.

Consider adding null safety and error handling:

-    private val gson = GsonBuilder().create()
+    private val gson = GsonBuilder()
+        .serializeNulls()
+        .create()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d8e4253 and 84262d7.

📒 Files selected for processing (14)
  • app/src/main/java/me/capcom/smsgateway/data/AppDatabase.kt (2 hunks)
  • app/src/main/java/me/capcom/smsgateway/data/Migrations.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/data/entities/Message.kt (3 hunks)
  • app/src/main/java/me/capcom/smsgateway/domain/MessageContent.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt (2 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/PostMessageRequest.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/MessagesRoutes.kt (2 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt (12 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/data/Message.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/data/SendRequest.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/data/StoredSendRequest.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/repositories/MessagesRepository.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/vm/MessageDetailsViewModel.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/ui/MessageDetailsFragment.kt (1 hunks)
🔇 Additional comments (20)
app/src/main/java/me/capcom/smsgateway/modules/messages/data/SendRequest.kt (1)

5-9: Verify impact of removing data class behavior.

Converting from data class to open class removes auto-generated equals(), hashCode(), toString(), copy(), and component functions. This could break existing code that relies on these behaviors.

#!/bin/bash
# Description: Search for SendRequest usage patterns that might be affected by the data class removal

# Check for equality comparisons
rg -A 2 -B 2 "SendRequest.*==" 

# Check for usage in hash-based collections (Set, Map)
rg -A 2 -B 2 "Set.*SendRequest|Map.*SendRequest"

# Check for copy() method usage
rg -A 2 -B 2 "\.copy\(\)" --type kotlin

# Check for destructuring assignments
rg -A 2 -B 2 "val \(.*\) = .*SendRequest"

# Check for toString() usage in logging
rg -A 2 -B 2 "SendRequest.*toString|log.*SendRequest"
app/src/main/java/me/capcom/smsgateway/ui/MessageDetailsFragment.kt (1)

43-43: Verify MessageContent.toString() provides user-friendly display.

The change correctly adapts to the new MessageContent type. Ensure that MessageContent.toString() returns appropriate text for UI display across all content types (Text, Data).

#!/bin/bash
# Description: Check MessageContent.toString() implementation and other UI usage

# Find MessageContent class definition and toString implementation
ast-grep --pattern $'sealed class MessageContent {
  $$$
}'

# Check for other UI usages of message content
rg -A 2 -B 2 "\.content\.toString\(\)|\.content\s" --type kotlin
app/src/main/java/me/capcom/smsgateway/modules/messages/data/Message.kt (2)

3-3: LGTM: Correct import for MessageContent.

The import from the domain package is appropriate for the MessageContent abstraction.


8-8: Verify complete migration from text to content property.

The change from String to MessageContent is correct for supporting typed message content. Ensure all code referencing message.text has been updated to use message.content.

#!/bin/bash
# Description: Check for any remaining references to the old text property

# Search for any remaining usage of .text property on Message objects
rg -A 2 -B 2 "\.text\b" --type kotlin

# Look for Message construction with text parameter
rg -A 2 -B 2 "Message\(" --type kotlin
app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt (2)

9-9: LGTM: Correct import for MessageContent.

The import from the domain package is appropriate.


208-208: LGTM: Proper wrapping of text content.

Correctly wraps the plain text message in MessageContent.Text() to align with the new typed content system. This maintains compatibility with the existing API while supporting the new domain model.

app/src/main/java/me/capcom/smsgateway/data/AppDatabase.kt (2)

27-27: LGTM: Database version increment for schema changes.

Correctly incremented version to 14 for the MessageContent migration.


56-59: ```shell
#!/bin/bash

Description: Extract the full MIGRATION_13_14 implementation to verify data copy, drop, and rename steps

rg -n -A 100 -B 0 "val MIGRATION_13_14" --type kotlin app/src/main/java/me/capcom/smsgateway/data/Migrations.kt


</details>
<details>
<summary>app/src/main/java/me/capcom/smsgateway/domain/MessageContent.kt (1)</summary>

`3-15`: **Well-designed domain model with proper abstractions.**

The sealed class approach is excellent for representing different message content types. The implementation follows Kotlin best practices with appropriate toString() overrides for each subclass.

</details>
<details>
<summary>app/src/main/java/me/capcom/smsgateway/modules/messages/vm/MessageDetailsViewModel.kt (2)</summary>

`9-9`: **Import updated for new domain model.**

The import change aligns with the broader refactoring to use `StoredSendRequest` instead of `MessageWithRecipients`.

---

`15-16`: **ViewModel updated to use new domain model.**

The type change from `MessageWithRecipients` to `StoredSendRequest` is consistent with the architectural changes described in the AI summary.

</details>
<details>
<summary>app/src/main/java/me/capcom/smsgateway/data/entities/Message.kt (2)</summary>

`10-13`: **Clean enum design for message types.**

The `MessageType` enum with `Text` and `Data` values provides clear type safety for distinguishing message content types.

---

`39-42`: ```shell
#!/bin/bash
# Display the full MIGRATION_13_14 definition to verify CREATE, INSERT, DROP, and RENAME logic
sed -n '1,200p' app/src/main/java/me/capcom/smsgateway/data/Migrations.kt
app/src/main/java/me/capcom/smsgateway/modules/messages/data/StoredSendRequest.kt (1)

7-15: Well-structured domain class with clear inheritance.

The StoredSendRequest class properly extends SendRequest and adds persistence-related fields. The constructor delegation and field organization are clean and follow good Kotlin practices.

app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/PostMessageRequest.kt (3)

11-13: Clean text message representation.

The TextMessage class provides a clear abstraction for text content.


17-18: Good backward compatibility approach.

Deprecating the old message field while maintaining it as nullable provides smooth migration path for existing clients.


25-26: Verify mutual exclusivity validation for message types.

The nullable textMessage and dataMessage fields allow flexibility, but ensure validation exists to prevent both being set simultaneously or both being null.

Check if validation logic exists for mutual exclusivity of message types:

#!/bin/bash
# Search for validation logic that ensures only one message type is provided
rg -A 5 -B 5 "textMessage.*dataMessage|message.*null|validation.*message" --type kt
app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/MessagesRoutes.kt (1)

87-93: LGTM! Port validation is correct.

The port range validation (0-65535) correctly covers the full range of valid port numbers for SMS data messages.

app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt (2)

328-371: LGTM! Well-structured content type handling.

The when statement properly handles both text and data message types with appropriate SMS API calls. The encryption/decryption logic is consistently applied to both content types.


290-291: ```shell
#!/usr/bin/env bash
set -e

echo "Extracting MessagesService.kt context..."
sed -n '250,330p' app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt

echo -e "\nSearching for repository usage in MessagesService.kt..."
rg -n "repository" -C3 app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
docs/api/swagger.json (3)

1079-1081: Mark the deprecated message field explicitly
OpenAPI supports a deprecated: true flag. Add "deprecated": true to the message property to signal tooling and clients that it should no longer be used.

@@ -1079,3 +1079,4 @@
           "type": "string",
+          "deprecated": true,
           "description": "The message text. This field is deprecated, use `textMessage` instead.",
           "maxLength": 65535
         },

1144-1156: Consider disallowing extra fields in TextMessage
To tighten the schema, add "additionalProperties": false to prevent unvalidated extra properties.

@@ -1144,6 +1144,7 @@
     "title": "TextMessage",
     "properties": {
       "text": {
+        "description": "Message text",
         "type": "string"
       }
     },
+    "additionalProperties": false,
     "required": [
       "text"
     ]

1157-1176: Enhance DataMessage schema with strict validation
Add "additionalProperties": false to disallow unspecified fields, and use OpenAPI's format: "byte" for the Base64 payload.

@@ -1161,6 +1161,7 @@
           "type": "string",
+          "format": "byte",
           "description": "Base64-encoded payload"
         },
         "port": {
@@ -1174,6 +1175,7 @@
         ],
+    "additionalProperties": false,
     "required": [
       "data",
       "port"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 12b1138 and 498f1fe.

📒 Files selected for processing (1)
  • docs/api/swagger.json (2 hunks)
🔇 Additional comments (2)
docs/api/swagger.json (2)

1131-1134: textMessage property addition looks good
The new textMessage field with a clear reference and description is properly defined and aligns with the domain model.


1135-1138: dataMessage property addition looks good
The new dataMessage field is correctly structured and its description clarifies mutual exclusivity.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
app/src/main/java/me/capcom/smsgateway/modules/receiver/MessagesReceiver.kt (1)

26-27: Remove commented-out code.

This commented line appears to be leftover from refactoring and should be removed to maintain code cleanliness.

-        val firstMessage = messages.first()
-//        val text = messages.joinToString(separator = "") { it.displayMessageBody }
-
+        val firstMessage = messages.first()
+
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d2357c0 and 70967d8.

📒 Files selected for processing (6)
  • app/src/main/AndroidManifest.xml (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/MessagesReceiver.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt (3 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/data/InboxMessage.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsEventPayload.kt (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt
🔇 Additional comments (3)
app/src/main/AndroidManifest.xml (1)

43-48: Verify the choice of port 53739 for data SMS.

The port number appears arbitrary. Please ensure this port is documented in your application documentation and doesn't conflict with other apps that might use data SMS.

Is port 53739 a standard or commonly used port for data SMS in Android applications?
app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsEventPayload.kt (1)

40-46: LGTM!

The new SmsDataReceived class follows the established pattern and properly distinguishes data SMS payloads from text SMS payloads.

app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt (1)

51-77: LGTM!

The refactoring to handle both text and data messages is well-implemented. The use of Base64 encoding with NO_WRAP flag is appropriate for transmitting binary data.

@capcom6 capcom6 force-pushed the feature/data-messages branch from 70967d8 to 56dbe2d Compare June 26, 2025 10:55
@capcom6 capcom6 marked this pull request as ready for review June 26, 2025 23:52
@github-actions
Copy link
Contributor

github-actions bot commented Jun 27, 2025

🤖 Pull request artifacts

file commit
app-release.apk 7395acd
app-release.aab 7395acd

@capcom6 capcom6 force-pushed the feature/data-messages branch from 3a1f5fc to 7395acd Compare June 27, 2025 13:38
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt (1)

361-368: Base64 error handling properly implemented.

The Base64 decoding error handling has been correctly implemented as suggested in the previous review, with proper exception catching and meaningful error messages.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a1f5fc and 7395acd.

📒 Files selected for processing (24)
  • README.md (3 hunks)
  • app/schemas/me.capcom.smsgateway.data.AppDatabase/14.json (1 hunks)
  • app/src/main/AndroidManifest.xml (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/data/AppDatabase.kt (2 hunks)
  • app/src/main/java/me/capcom/smsgateway/data/Migrations.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/data/entities/Message.kt (3 hunks)
  • app/src/main/java/me/capcom/smsgateway/domain/MessageContent.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt (2 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/PostMessageRequest.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/MessagesRoutes.kt (2 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt (12 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/data/Message.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/data/SendRequest.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/data/StoredSendRequest.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/repositories/MessagesRepository.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/vm/MessageDetailsViewModel.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/MessagesReceiver.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt (3 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/data/InboxMessage.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsEventPayload.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/ui/MessageDetailsFragment.kt (1 hunks)
  • app/src/test/java/me/capcom/smsgateway/data/entities/MessageWithRecipientsTest.kt (3 hunks)
  • docs/api/swagger.json (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (23)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/data/Message.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt
  • app/src/main/java/me/capcom/smsgateway/ui/MessageDetailsFragment.kt
  • app/src/main/java/me/capcom/smsgateway/data/AppDatabase.kt
  • app/src/test/java/me/capcom/smsgateway/data/entities/MessageWithRecipientsTest.kt
  • app/src/main/AndroidManifest.xml
  • app/src/main/java/me/capcom/smsgateway/modules/messages/data/SendRequest.kt
  • app/src/main/java/me/capcom/smsgateway/modules/messages/vm/MessageDetailsViewModel.kt
  • app/src/main/java/me/capcom/smsgateway/data/Migrations.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsEventPayload.kt
  • app/src/main/java/me/capcom/smsgateway/data/entities/Message.kt
  • app/src/main/java/me/capcom/smsgateway/domain/MessageContent.kt
  • app/src/main/java/me/capcom/smsgateway/modules/messages/data/StoredSendRequest.kt
  • app/schemas/me.capcom.smsgateway.data.AppDatabase/14.json
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/MessagesReceiver.kt
  • app/src/main/java/me/capcom/smsgateway/modules/messages/repositories/MessagesRepository.kt
  • README.md
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/MessagesRoutes.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/PostMessageRequest.kt
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt
  • docs/api/swagger.json
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/data/InboxMessage.kt
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build / build-apk
🔇 Additional comments (6)
app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt (6)

15-15: Import additions look appropriate for the new functionality.

The new imports for Base64, MessageContent, SendParams, StoredSendRequest, and MessagesRepository are all necessary for supporting data messages and the repository-based architecture.

Also applies to: 24-24, 34-34, 36-36, 38-38


91-95: Excellent refactoring to use repository pattern.

The delegation to messages.enqueue(request) and extraction of priority from request.params represents a clean separation of concerns and simplifies the service logic.


171-171: Consistent repository usage and parameter extraction.

The changes maintain the same logic flow while properly using the repository pattern and extracting priority from request parameters.

Also applies to: 174-174, 177-177, 187-187


214-215: Method signature updated correctly for new request structure.

The change from MessageWithRecipients to StoredSendRequest aligns with the repository pattern, and the TTL check properly uses request.params.validUntil.


262-264: SIM selection logic properly adapted to new parameter structure.

The changes correctly extract SIM number from SendParams and use the request ID for round-robin selection, maintaining the same logic with the new data structure.

Also applies to: 274-274, 283-283, 286-286


328-378: Excellent implementation of MessageContent handling.

The new message content abstraction is well-implemented with proper separation between Text and Data message types. Key strengths:

  • Consistent encryption/decryption handling for both content types
  • Proper multipart message handling for text messages
  • Correct Base64 decoding with error handling for data messages
  • Appropriate use of port parameter for data SMS

The implementation addresses the past review comment about Base64 error handling and provides a solid foundation for supporting data messages.

@capcom6 capcom6 merged commit d19025f into master Jun 27, 2025
3 checks passed
@capcom6 capcom6 deleted the feature/data-messages branch June 27, 2025 23:00
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2025
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