Sort instant commands universal-first preserving backend order#6418
Sort instant commands universal-first preserving backend order#6418
Conversation
Extends sortedByAvailability with a tier tie-breaker so command suggestions surface universal commands (set != moderation_set) before contextual ones. The sort is stable, so within each tier the input order from the backend's Channel.config.commands is preserved — no client-side opinion on relative order between commands of the same tier. Affects the Compose composer suggestion list (via MessageComposerController.orderedForComposer) and the Compose attachment command picker (AttachmentCommandPicker), which both call into sortedByAvailability.
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThis PR modifies command suggestion ordering to prioritize non-moderation commands within availability tiers, implementing a two-level stable sort, along with documentation clarification and updated test validation. ChangesCommand Sorting and Availability Logic
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
SDK Size Comparison 📏
|
|



Goal
Address Issue #8 — Instant commands sort order from the SDK Testing Feedback Notion board. Today, the suggestion list shows backend commands in raw order, which mixes universal commands (
giphy) with moderation-set ones (ban,unban,mute,unmute) — moderation commands appear right aftergiphyeven when the user is composing a normal message, which is noisy and not what most users expect to see.Implementation
sortedByAvailabilitygains a tier tie-breaker. The sort is now keyed first by availability for the currentMessageAction, then by universal-first (set != "moderation_set"before moderation-set commands).Channel.config.commandsis preserved — no client-side opinion on the relative order between commands of the same tier. Backends that already prefer a specific order (e.g.giphy, ban, unban, mute, unmutein the Stream chat backend) keep their intended order.sortedByAvailabilityis the only place that orders the suggestion list — both the Compose composer suggestion list (viaMessageComposerController.orderedForComposer) and the Compose attachment command picker (AttachmentCommandPicker) inherit the new ordering.MODERATION_COMMAND_SETstaysprivatetoCommandAvailability.kt.@InternalStreamChatApiboundary unchanged.MessageComposerControllerTestextended to assert the universal-first ordering on top of the existing availability tier.Important
Decision — sort by tier, not by hardcoded command list
Considered hardcoding a preference list (e.g.
[giphy, ban, unban, mute, unmute]) but rejected: the SDK shouldn't carry an opinion about specific command names. Sorting byset(a backend-declared property) keeps the SDK generic and lets the backend evolve commands without a client release. Stable sort preserves whatever order the backend provides within each tier.Testing
/in the composer.giphy) appear first; moderation commands (ban,unban,mute,unmute) follow. Within each group, the order matches the backend'sChannel.config.commandsdeclaration order.Summary by CodeRabbit
Bug Fixes
Tests