Make canSendMessage actually gate ChatInput's FAB click#5
Merged
Conversation
ChatInput accepts a canSendMessage: Boolean = true parameter. The
contract from the host's perspective is "set to false to block
sends right now" — useful while a moderation hook is evaluating,
during reconnect, while a rate-limit cool-down is active, etc.
Today the flag only changes the FAB's container colour (dim
surface variant vs primary). The onClick handler dispatches
onSendMessage / onSendMedia regardless. So a host setting
canSendMessage = false sees the dimmed pill, taps it, and the
message goes out anyway — exact opposite of the contract the
parameter name suggests.
Add an early return at the top of the FAB's onClick:
onClick = onClick@{
if (!canSendMessage) return@onClick
...existing send logic...
}
The disabled-state IconButton (shown when the field is empty)
was already correctly gated via Compose's `enabled = false` —
this fix only affects the active FAB shown when the field has
text or a selected file.
No host API change. Hosts that ignored canSendMessage (left it
default true) see no difference. Hosts that set it false now get
the behaviour the parameter advertises.
Companion ChatInput Compose UI test is on
ethora-sdk-android/tf/test-scaffold (PR #3); will add an explicit
assertion that canSendMessage = false suppresses the callback in
a follow-up commit on that branch.
e92348a to
568017c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
`ChatInput` accepts a `canSendMessage: Boolean = true` parameter. The contract the parameter name suggests is "set to false to block sends right now."
Today the flag only changes the FAB's container colour (dim `surfaceVariant` vs `primary`). The `onClick` handler dispatches `onSendMessage` / `onSendMedia` regardless. A host setting `canSendMessage = false` sees the dimmed pill, the user taps it, and the message goes out anyway — the exact opposite of what the contract suggests.
Fix
Add an early return at the top of the FAB's `onClick`:
```kotlin
onClick = onClick@{
if (!canSendMessage) return@onClick
// ...existing send logic...
}
```
The disabled-state `IconButton` (shown when the field is empty) was already correctly gated via Compose's `enabled = false` — this only affects the active FAB shown when the field has text or a selected file.
Behavior change vs no change
Likely-affected callers: any host using `canSendMessage` to mean "block sends" — e.g. while a moderation/compliance hook evaluates, while reconnecting, while a rate-limit cool-down is active. They should benefit from this fix because the parameter now matches its contract. If anyone is relying on the old "always-fires" behavior to do something other than block sends, this change breaks that — happy to discuss alternative solutions in review.
Why this came up
Surfaced while threading semantic `testTag`s through `ChatInput` (PR #4) — needed to understand the click contract to tag the active vs disabled paths correctly. Flagged as one of two findings (the other was about `isDeleted` rendering, which I was wrong about — the tombstone is already implemented).
Test plan