Skip to content

Sort instant commands universal-first preserving backend order#6418

Open
andremion wants to merge 1 commit intodevelopfrom
fix/sdk-instant-commands-sort
Open

Sort instant commands universal-first preserving backend order#6418
andremion wants to merge 1 commit intodevelopfrom
fix/sdk-instant-commands-sort

Conversation

@andremion
Copy link
Copy Markdown
Contributor

@andremion andremion commented May 6, 2026

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 after giphy even when the user is composing a normal message, which is noisy and not what most users expect to see.

Implementation

  • sortedByAvailability gains a tier tie-breaker. The sort is now keyed first by availability for the current MessageAction, then by universal-first (set != "moderation_set" before moderation-set commands).
  • Sort stays stable. Within each tier the input order from the backend's Channel.config.commands is 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, unmute in the Stream chat backend) keep their intended order.
  • Single sort site, two consumers. sortedByAvailability is the only place that orders the suggestion list — both the Compose composer suggestion list (via MessageComposerController.orderedForComposer) and the Compose attachment command picker (AttachmentCommandPicker) inherit the new ordering.
  • No new constants leak out. MODERATION_COMMAND_SET stays private to CommandAvailability.kt. @InternalStreamChatApi boundary unchanged.
  • Tests. MessageComposerControllerTest extended 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 by set (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

  1. Run the Compose sample app on this branch and open any channel.
  2. Tap the slash icon (commands picker) or type / in the composer.
    • Expected: universal commands (e.g. giphy) appear first; moderation commands (ban, unban, mute, unmute) follow. Within each group, the order matches the backend's Channel.config.commands declaration order.
  3. Compose a reply (long-press a message → "Reply") and reopen the commands picker.
    • Expected: same ordering as step 2.
  4. Repeat for any composer action that affects command availability (edit, thread reply).
    • Expected: commands unavailable for that action are pushed to the bottom; within the available group, universal-first ordering still applies.

Summary by CodeRabbit

  • Bug Fixes

    • Improved command suggestion ordering in the message composer—standard commands now appear before moderation-specific commands when typing a slash.
  • Tests

    • Added test coverage for command suggestion ordering behavior.

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.
@andremion andremion added the pr:improvement Improvement label May 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled (or ignored for dependabot PRs).

🎉 Great job! This PR is ready for review.

@andremion
Copy link
Copy Markdown
Contributor Author

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c83daee1-ea08-47a7-ab89-a37d222d4b7d

📥 Commits

Reviewing files that changed from the base of the PR and between 75cafde and 3fa1a90.

📒 Files selected for processing (3)
  • stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/composer/MessageComposerController.kt
  • stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/state/messages/composer/CommandAvailability.kt
  • stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/feature/messages/composer/MessageComposerControllerTest.kt

Walkthrough

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

Changes

Command Sorting and Availability Logic

Layer / File(s) Summary
Core Sorting Logic
src/main/kotlin/io/getstream/chat/android/ui/common/state/messages/composer/CommandAvailability.kt
sortedByAvailability() extension function now applies a two-level stable sort: first by availability for the given action, then by non-moderation commands (prioritized over moderation-set commands).
Documentation & Integration
src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/composer/MessageComposerController.kt
KDoc for orderedForComposer() is updated to clarify that sortedByAvailability is applied when activeCommandEnabled is true, with unchanged behavior in legacy mode.
Test Validation
src/test/kotlin/io/getstream/chat/android/ui/common/feature/messages/composer/MessageComposerControllerTest.kt
New test verifies that command suggestions follow universal-first ordering (non-moderation before moderation) while preserving backend order within each tier, and that this order is maintained when switching modes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A sorting rabbit's hop of glee,
Two tiers now dance in harmony!
Commands reorder, swift and bright,
Universal magic comes first in sight,
Moderation whispers follow behind,
A better order, carefully signed. 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% 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
Title check ✅ Passed The title clearly and concisely summarizes the primary change: sorting instant commands universally-first while preserving backend order.
Description check ✅ Passed The description covers Goal, Implementation, and Testing sections with comprehensive details. UI changes and contributor checklist sections are not applicable to this non-visual change.
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.

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

✨ 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 fix/sdk-instant-commands-sort

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.82 MB 5.82 MB 0.00 MB 🟢
stream-chat-android-ui-components 11.02 MB 11.02 MB 0.00 MB 🟢
stream-chat-android-compose 12.37 MB 12.38 MB 0.00 MB 🟢

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 6, 2026

@andremion andremion marked this pull request as ready for review May 6, 2026 09:53
@andremion andremion requested a review from a team as a code owner May 6, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:improvement Improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant