Skip to content

[messages] add work hours support#390

Open
capcom6 wants to merge 1 commit into
masterfrom
messages/work-hours-support
Open

[messages] add work hours support#390
capcom6 wants to merge 1 commit into
masterfrom
messages/work-hours-support

Conversation

@capcom6

@capcom6 capcom6 commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added configurable working hours scheduling (default 09:00–19:00) with an enable toggle and new settings.
    • Added time pickers for work-hours start/end; start/end fields are shown only when enabled.
  • Behavior Updates
    • Non-expedited message delivery is now constrained to the working-hours window (including wrap-around past midnight); delivery pauses until the next upcoming start.
    • Expedited messages remain unconstrained by working hours.
    • If start equals end, the window is treated as always active.
  • Documentation
    • Updated the README to mention working-hours scheduling.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e9bc73ed-2e81-4c4e-b043-199f6d2bdf74

📥 Commits

Reviewing files that changed from the base of the PR and between 53dcdba and 559794b.

📒 Files selected for processing (6)
  • README.md
  • app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesSettings.kt
  • app/src/main/java/me/capcom/smsgateway/ui/settings/MessagesSettingsFragment.kt
  • app/src/main/res/values/strings.xml
  • app/src/main/res/xml/messages_preferences.xml
✅ Files skipped from review due to trivial changes (2)
  • README.md
  • app/src/main/res/values/strings.xml
🚧 Files skipped from review as they are similar to previous changes (4)
  • app/src/main/res/xml/messages_preferences.xml
  • app/src/main/java/me/capcom/smsgateway/ui/settings/MessagesSettingsFragment.kt
  • app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesSettings.kt

Walkthrough

Adds configurable work-hours scheduling for SMS delivery. MessagesSettings stores and validates the work-hours window, MessagesService uses it to gate enqueueing and pending sends, and the settings UI adds controls for enabling and editing the window.

Changes

Work Hours SMS Scheduling

Layer / File(s) Summary
Work hours settings model, storage, and export/import
app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesSettings.kt
Adds work-hours state, window evaluation, next-start calculation, storage keys, export/import handling, and validation.
Service-level work-hours scheduling and gating
app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt
Updates enqueue timing, adds deferred work-hours limiting, and gates pending sends for non-expedited messages.
Settings UI: work hours preferences and time picker
app/src/main/res/xml/messages_preferences.xml, app/src/main/res/values/strings.xml, app/src/main/java/me/capcom/smsgateway/ui/settings/MessagesSettingsFragment.kt, README.md
Adds the working-hours preference section, related strings, time-picker editing flow, and feature documentation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MessagesService
  participant MessagesSettings
  participant SendMessagesWorker
  MessagesService->>MessagesSettings: nextWorkHoursStart()
  MessagesSettings-->>MessagesService: future start time
  MessagesService->>SendMessagesWorker: start(context, true, startTime)
  MessagesService->>MessagesService: delay until next work-hours start
Loading

Possibly related PRs

  • capcom6/android-sms-gateway#277: Modifies MessagesService.sendPendingMessages throttling for non-expedited messages, which is the same execution path extended here with work-hours gating.
  • capcom6/android-sms-gateway#351: Introduces scheduling based on scheduleAt in MessagesService, overlapping with the worker-start timing path updated here.
  • capcom6/android-sms-gateway#362: Changes MessagesService worker-start logic around scheduleAt and the boolean passed to SendMessagesWorker, directly related to the enqueue timing branch used here.

Suggested labels: ready

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% 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 clearly matches the main change: adding work-hours support to the messages feature.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch messages/work-hours-support

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: 4

🤖 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/messages/MessagesService.kt`:
- Around line 124-125: The SendMessagesWorker.start() method is being called
unconditionally with the replace flag set to true in the else block, which
overwrites any previously queued work and delays pending messages. Instead of
always replacing the work, add a condition to check whether work is already
scheduled before deciding to replace it. Only pass true to the replace parameter
if there is no existing scheduled work, otherwise pass false to preserve the
already queued earlier run.

In `@app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesSettings.kt`:
- Around line 78-82: The isInWorkHours() method does not handle the edge case
where startMinutes equals endMinutes, causing it to always return false and
leading to indefinite deferral of non-expedited messages. Add an explicit check
at the beginning of the return statement to handle the case where startMinutes
equals endMinutes (treat this as always being in work hours), then proceed with
the existing logic for cases where startMinutes is less than or greater than
endMinutes. Apply the same fix to the nextWorkHoursStart() method (referenced in
the "Also applies to" comment) to ensure consistent behavior across both
methods.
- Around line 267-283: The WORK_HOURS_START and WORK_HOURS_END cases in the
import() method accept arbitrary string values without validating their time
format, allowing invalid values to be persisted and later silently coerced to
zero minutes by parseTimeMinutes(). Before calling storage.set(key, newValue) in
both the WORK_HOURS_START and WORK_HOURS_END cases, validate that the newValue
string matches the expected time format (HH:MM) using a regex pattern or parsing
attempt, and either reject invalid values by returning false or using a more
informative default that indicates validation failed. This same validation
should also be applied to the other work-hours related cases mentioned at lines
113-117.

In
`@app/src/main/java/me/capcom/smsgateway/ui/settings/MessagesSettingsFragment.kt`:
- Line 60: The String.format call formatting the time display (with pattern
"%02d:%02d" for hours and minutes) uses the default locale, which can produce
non-ASCII numerals on some devices and break downstream parsing. Fix this by
specifying Locale.US as the first parameter to String.format before the format
string to ensure consistent ASCII numerals are always used for the persisted
HH:mm time format.
🪄 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: 1a347e29-2d38-4d66-b8d8-e10526418c0f

📥 Commits

Reviewing files that changed from the base of the PR and between 361de56 and a7ce76e.

📒 Files selected for processing (5)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesSettings.kt
  • app/src/main/java/me/capcom/smsgateway/ui/settings/MessagesSettingsFragment.kt
  • app/src/main/res/values/strings.xml
  • app/src/main/res/xml/messages_preferences.xml

Comment thread app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesSettings.kt Outdated
Comment thread app/src/main/java/me/capcom/smsgateway/ui/settings/MessagesSettingsFragment.kt Outdated
@capcom6 capcom6 force-pushed the messages/work-hours-support branch 2 times, most recently from 9dd438c to 82266a8 Compare June 23, 2026 02:29

@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 `@app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesSettings.kt`:
- Line 152: The VERSION_CODE constant in MessagesSettings has been incorrectly
decremented to 1, which violates the requirement for monotonic increasing
migration versions. This will cause already-migrated installations with higher
version codes to be treated as if they need older schema migrations, breaking
the migration sequence. Revert VERSION_CODE to its previous value (which was
higher than 1). Migration version codes must only increase or remain unchanged,
never decrease.
🪄 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: 6a9fd13c-aa8a-4e75-8b6b-a11dae090c77

📥 Commits

Reviewing files that changed from the base of the PR and between 82266a8 and 698f35b.

📒 Files selected for processing (1)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesSettings.kt

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

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

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 `@app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesSettings.kt`:
- Line 152: The VERSION_CODE constant in MessagesSettings has been incorrectly
decremented to 1, which violates the requirement for monotonic increasing
migration versions. This will cause already-migrated installations with higher
version codes to be treated as if they need older schema migrations, breaking
the migration sequence. Revert VERSION_CODE to its previous value (which was
higher than 1). Migration version codes must only increase or remain unchanged,
never decrease.
🪄 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: 6a9fd13c-aa8a-4e75-8b6b-a11dae090c77

📥 Commits

Reviewing files that changed from the base of the PR and between 82266a8 and 698f35b.

📒 Files selected for processing (1)
  • app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesSettings.kt
🛑 Comments failed to post (1)
app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesSettings.kt (1)

152-152: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Do not decrement settings migration version code.

Line 152 regresses VERSION_CODE to 1. That can rewrite already-migrated installs (e.g., stored version 2) back to an older schema version and break future migration sequencing. Keep migration versions monotonic increasing.

Suggested fix
-        private const val VERSION_CODE = 1
+        private const val VERSION_CODE = 2
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

        private const val VERSION_CODE = 2
🤖 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/messages/MessagesSettings.kt`
at line 152, The VERSION_CODE constant in MessagesSettings has been incorrectly
decremented to 1, which violates the requirement for monotonic increasing
migration versions. This will cause already-migrated installations with higher
version codes to be treated as if they need older schema migrations, breaking
the migration sequence. Revert VERSION_CODE to its previous value (which was
higher than 1). Migration version codes must only increase or remain unchanged,
never decrease.

@capcom6 capcom6 force-pushed the messages/work-hours-support branch from 698f35b to f2f4d4d Compare June 23, 2026 05:06
@capcom6 capcom6 marked this pull request as ready for review June 23, 2026 07:25
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

🤖 Pull request artifacts

file commit
app-release.apk 559794b
app-release.aab 559794b
app-insecure.apk 559794b
app-insecure.aab 559794b

@capcom6 capcom6 force-pushed the messages/work-hours-support branch from f2f4d4d to 36c0cca Compare June 24, 2026 02:06
@capcom6 capcom6 added the ready label Jun 24, 2026
@capcom6 capcom6 force-pushed the messages/work-hours-support branch from 36c0cca to d23aed7 Compare June 25, 2026 00:13
@github-actions github-actions Bot removed the ready label Jun 25, 2026
@capcom6 capcom6 added the ready label Jun 25, 2026
@capcom6 capcom6 force-pushed the messages/work-hours-support branch from d23aed7 to 53dcdba Compare July 2, 2026 02:18
@github-actions github-actions Bot removed the ready label Jul 2, 2026
@capcom6 capcom6 added the ready label Jul 2, 2026
@capcom6 capcom6 force-pushed the messages/work-hours-support branch from 53dcdba to 559794b Compare July 8, 2026 01:11
@github-actions github-actions Bot removed the ready label Jul 8, 2026
@capcom6 capcom6 added the ready label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant