Skip to content

fix: prevent sending empty title or body in push messages#2904

Open
Bhaaru2 wants to merge 4 commits intoappwrite:mainfrom
Bhaaru2:fix-first-issue
Open

fix: prevent sending empty title or body in push messages#2904
Bhaaru2 wants to merge 4 commits intoappwrite:mainfrom
Bhaaru2:fix-first-issue

Conversation

@Bhaaru2
Copy link

@Bhaaru2 Bhaaru2 commented Mar 8, 2026

What does this PR do?

Fixes #968

Adds validation to prevent sending push messages when the title or body contains only whitespace.

The inputs are trimmed before submission, and if either field is empty an error notification is shown to the user.

Test Plan

  1. Open the Messaging section in the console
  2. Try creating a push message with only spaces in the title or body
  3. The system now prevents submission and shows an error notification

Related Issues

Fixes #968

Summary by CodeRabbit

  • Bug Fixes
    • Push notification creation now trims title and body and validates they are not empty, showing an immediate error if required fields are missing.
    • Draft status is preserved correctly during submission so submissions reflect the intended draft setting; success and error flows remain unchanged.

@appwrite
Copy link

appwrite bot commented Mar 8, 2026

Console (appwrite/console)

Project ID: 688b7bf400350cbd60e9

Sites (1)
Site Status Logs Preview QR
 console-stage
688b7cf6003b1842c9dc
Queued Queued Authorize Preview URL QR Code

Tip

Schedule functions to run as often as every minute with cron expressions

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 8, 2026

Warning

Rate limit exceeded

@Bhaaru2 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f340047b-bcdb-4894-affb-10d9d91255fc

📥 Commits

Reviewing files that changed from the base of the PR and between 7f018f4 and a314c4b.

📒 Files selected for processing (1)
  • src/routes/(console)/project-[region]-[project]/messaging/create-[type]/(type)/push.svelte

Walkthrough

A push notification creation component was updated to add local draft tracking and input trimming. The create() function now copies draft into isDraft, trims title and body, validates that non-draft messages have non-empty trimmed title and body (emitting an error notification and returning early if invalid), assigns trimmed values back to title and body, and sends draft: isDraft in the API request. Existing try/catch, success, and error handling remain unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: prevent sending empty title or body in push messages' directly and clearly summarizes the main change: validation to prevent sending push messages with empty titles or bodies.
Linked Issues check ✅ Passed The code changes fully satisfy issue #968 by implementing validation to prevent sending push messages with empty or whitespace-only titles and bodies, and showing error notifications when validation fails.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective: input trimming, validation for empty fields, error notification, and draft state handling are all in scope for fixing issue #968.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 8, 2026

Greptile Summary

This PR adds whitespace-trim validation to the push message creation flow, preventing messages with whitespace-only titles or bodies from being sent. It also fixes a subtle pre-existing bug where draft could remain true after a failed "Save as draft" attempt, which would have caused a subsequent "Create" click to incorrectly send draft: true to the API.

Key changes:

  • isDraft captures the current draft state before resetting draft = false, correctly isolating the draft flag for the API call and preventing stale state across retries
  • Validation is correctly gated with if (!isDraft && ...), so draft saves properly bypass the whitespace check
  • Trimmed values are conditionally written back to the component variables (if (title !== undefined) title = trimmedTitle) before the API call, handling the undefined case so absent fields are not converted to empty strings in the API payload

Remaining concerns from prior review rounds:

  • The error message 'Title and message body cannot be empty.' still fires when only one of the two fields is whitespace-only, which is misleading to users — this was flagged in prior review threads but has not been addressed
  • Drafts with a whitespace-only title or body will have those fields trimmed to "" and sent to the API as explicit empty strings rather than being omitted; depending on the Appwrite API's handling of title: "" vs. absent title, this could cause unexpected validation errors for draft saves

Confidence Score: 3/5

  • Functional fix is logically correct, but multiple issues flagged in prior review rounds remain unresolved.
  • The core validation logic (whitespace check, draft bypass, trimmed-value write-back, and stale-draft-flag fix) is implemented correctly. However, the misleading error message has not been addressed despite being flagged twice in previous review threads, and draft saves with whitespace-only fields will still pass "" to the API rather than omitting those fields. These are not blocking regressions, but they represent UX issues and a potential API incompatibility that reduce confidence in the PR being fully ready to merge.
  • src/routes/(console)/project-[region]-[project]/messaging/create-[type]/(type)/push.svelte — specifically the error message string on line 48 and the draft payload behavior for whitespace-only fields.

Important Files Changed

Filename Overview
src/routes/(console)/project-[region]-[project]/messaging/create-[type]/(type)/push.svelte Adds whitespace-trim validation before push message submission; draft bypass is correctly implemented, but trimmed values are written back to component variables while the API call still references the original variable names (which now hold trimmed values), and several issues from prior review rounds remain unaddressed.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User clicks Create or Save as Draft] --> B[create function invoked]
    B --> C[Capture isDraft from draft\nReset draft to false]
    C --> D[Compute trimmedTitle and trimmedBody]
    D --> E{isDraft?}
    E -- No --> F{trimmedTitle or trimmedBody empty?}
    F -- Yes --> G[Show error notification\nReturn early - no API call]
    F -- No --> H[Assign trimmed values back to title and body]
    E -- Yes --> H
    H --> I[Call Appwrite SDK createPush\nwith draft: isDraft]
    I --> J{API Response}
    J -- Success --> K[Show success notification\nNavigate to message page]
    J -- Failure --> L[Show error notification\ntrackError called]
Loading

Last reviewed commit: a314c4b

Copy link
Contributor

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/routes/`(console)/project-[region]-[project]/messaging/create-[type]/(type)/push.svelte:
- Around line 39-45: The validation block in push.svelte exits early when title
or body are empty but doesn't clear the shared draft state set by saveAsDraft(),
causing subsequent sends to still carry draft: true; before the early return in
the if (!title?.trim() || !body?.trim()) block, reset the draft flag (the shared
state mutated by saveAsDraft(), e.g., clear or set draft = false or call the
counterpart resetDraft/clearDraft helper) so that subsequent Create actions
won't include draft: true, then keep the addNotification call and return as-is.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5e7dbb6f-d81d-4217-8d82-e6667d2fc7e6

📥 Commits

Reviewing files that changed from the base of the PR and between 6138b73 and b3ca948.

📒 Files selected for processing (1)
  • src/routes/(console)/project-[region]-[project]/messaging/create-[type]/(type)/push.svelte

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.

🐛 Bug Report: Don't Allow Empty Title & Message Body for Messaging

2 participants