fix: custom doUploadRequest permission adjustments#3243
Conversation
π WalkthroughWalkthroughUpload eligibility now uses attachment-manager state and composer configuration instead of channel capabilities, while the file input is always rendered and no longer disabled by upload or cooldown state. ChangesUpload eligibility
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: π₯ 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.
Caution
Some comments are outside the diff and canβt be posted inline due to platform limitations.
β οΈ Outside diff range comments (1)
src/components/MessageComposer/AttachmentSelector/AttachmentSelector.tsx (1)
106-134: π― Functional Correctness | π΄ Critical | β‘ Quick winUpdate the upload eligibility check to match the new logic.
SimpleAttachmentSelectorstill relies onchannelCapabilities['upload-file']to determine visibility. IfuploadFileis the only available action because custom upload requests are permitted (despite the channel capability missing), this component will incorrectly evaluate tonulland completely hide the upload button.Update the check to use the new eligibility logic based on
useAttachmentManagerState.π Proposed fix
- const { channelCapabilities } = useChannelStateContext(); + const { hasAvailableUploadSlots, hasCustomDoUploadRequest, isUploadEnabled } = + useAttachmentManagerState(); const { t } = useTranslationContext(); const inputRef = useRef<HTMLInputElement | null>(null); const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null); const id = useStableId(); const isCooldownActive = useIsCooldownActive(); const messageComposer = useMessageComposerController(); + const channelConfig = messageComposer.channel.getConfig(); const { command } = useStateStore( messageComposer.textComposer.state, textComposerStateSelector, ); // Visually hidden via a CSS transition while a command is active; keep it out // of the a11y tree and tab order without setting `display: none`. const inertProps = useInertWhenHidden(!!command, { setHiddenAttribute: false }); useEffect(() => { if (!buttonElement) return; const handleKeyUp = (event: KeyboardEvent) => { if (![' ', 'Enter'].includes(event.key) || !inputRef.current) return; event.preventDefault(); inputRef.current.click(); }; buttonElement.addEventListener('keyup', handleKeyUp); return () => { buttonElement.removeEventListener('keyup', handleKeyUp); }; }, [buttonElement]); - if (!channelCapabilities['upload-file']) return null; + const canUpload = + (!hasCustomDoUploadRequest && channelConfig?.uploads && isUploadEnabled) || + (hasCustomDoUploadRequest && hasAvailableUploadSlots); + + if (!canUpload) return null;π€ 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 `@src/components/MessageComposer/AttachmentSelector/AttachmentSelector.tsx` around lines 106 - 134, Update the visibility guard in SimpleAttachmentSelector to use the eligibility state from useAttachmentManagerState instead of channelCapabilities['upload-file']. Preserve the existing null return when uploads are not eligible, while allowing the selector to remain visible when custom upload requests make uploadFile available despite the channel capability.
π€ 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.
Outside diff comments:
In `@src/components/MessageComposer/AttachmentSelector/AttachmentSelector.tsx`:
- Around line 106-134: Update the visibility guard in SimpleAttachmentSelector
to use the eligibility state from useAttachmentManagerState instead of
channelCapabilities['upload-file']. Preserve the existing null return when
uploads are not eligible, while allowing the selector to remain visible when
custom upload requests make uploadFile available despite the channel capability.
βΉοΈ Review info
βοΈ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c28c9e5b-c217-4005-af19-d8849a0da453
π Files selected for processing (3)
src/components/MessageComposer/AttachmentSelector/AttachmentSelector.tsxsrc/components/MessageComposer/hooks/useAttachmentManagerState.tssrc/components/ReactFileUtilities/UploadButton.tsx
π€ Files with no reviewable changes (1)
- src/components/ReactFileUtilities/UploadButton.tsx
π― Goal
Ref: https://getstream.slack.com/archives/C02R5UCGN6N/p1784023573649669
Relies on: GetStream/stream-chat-js#1800
Summary by CodeRabbit