Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ open class MessageListPage {
val commandsButton get() = By.res("Stream_ComposerCommandsButton")
val commandSuggestionList get() = By.res("Stream_CommandSuggestionList")
val commandSuggestionListTitle get() = By.res("Stream_CommandSuggestionListTitle")
val userSuggestion get() = By.res("Stream_UserSuggestionItem")
val userSuggestion get() = By.res("Stream_SuggestionItem")
val giphyButton get() = By.res("Stream_SuggestionListGiphyButton")
val attachmentsButton get() = By.res("Stream_ComposerAttachmentsButton")
val quotedMessage get() = By.res("Stream_QuotedMessage")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class ChatsActivity : ComponentActivity() {
ChatListContentMode.Channels,
ChatListContentMode.Mentions,
-> AppBottomBarOption.CHATS

ChatListContentMode.Threads -> AppBottomBarOption.THREADS
}
AppBottomBar(
Expand Down
94 changes: 86 additions & 8 deletions stream-chat-android-compose/api/stream-chat-android-compose.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
import io.getstream.chat.android.compose.ui.components.composer.MessageInput
import io.getstream.chat.android.compose.ui.messages.composer.actions.AudioRecordingActions
import io.getstream.chat.android.compose.ui.messages.composer.internal.suggestions.CommandSuggestionList
import io.getstream.chat.android.compose.ui.messages.composer.internal.suggestions.MentionSuggestionList
import io.getstream.chat.android.compose.ui.messages.composer.internal.suggestions.SuggestionsMenu
import io.getstream.chat.android.compose.ui.messages.composer.internal.suggestions.UserSuggestionList
import io.getstream.chat.android.compose.ui.theme.ChatTheme
import io.getstream.chat.android.compose.ui.theme.ComposerConfig
import io.getstream.chat.android.compose.ui.theme.LocalChatUiConfig
Expand All @@ -73,6 +73,7 @@
import io.getstream.chat.android.models.User
import io.getstream.chat.android.previewdata.PreviewCommandData
import io.getstream.chat.android.previewdata.PreviewUserData
import io.getstream.chat.android.ui.common.feature.messages.composer.mention.Mention
import io.getstream.chat.android.ui.common.state.messages.Edit
import io.getstream.chat.android.ui.common.state.messages.Reply
import io.getstream.chat.android.ui.common.state.messages.composer.MessageComposerState
Expand All @@ -99,14 +100,20 @@
* @param onCancelAction Handler for the cancel button on Message actions, such as Edit and Reply.
* @param onLinkPreviewClick Handler when the user taps on a link preview.
* @param onCancelLinkPreviewClick Handler when the user taps on the cancel link preview.
* @param onUserSelected Handler when the user taps on a user suggestion item.
* @param onUserSelected Legacy handler that fires only when the user taps a user suggestion item.
* Kept for backward compatibility; new callers should use [onMentionSelected], which receives every
* mention type including users. Note both callbacks fire on a user tap: a custom [onUserSelected]
* runs in addition to [onMentionSelected], so the default [onMentionSelected] still inserts the
* mention. To replace the default selection behavior, override [onMentionSelected].
* @param onCommandSelected Handler for every tap on a command suggestion item, including taps on
* disabled items. The default emits [MessageComposerViewEvent.CommandUnavailable] on
* [MessageComposerViewModel.events] when the command is not available for the current action;
* overrides replace that behavior and become responsible for their own filtering and feedback.
* @param onAlsoSendToChannelChange Handler when the "Also send to channel" checkbox is changed.
* @param onActiveCommandDismiss Called when the user taps the dismiss button on the active command chip.
* @param recordingActions The actions that can be performed on an audio recording.
* @param onMentionSelected Handler when the user taps any mention suggestion item. This is the
* canonical callback for all mention selections.
* @param input Customizable composable that represents the input field for the composer, [MessageInput] by default.
*/
@Composable
Expand All @@ -124,14 +131,15 @@
onCancelAction: () -> Unit = { viewModel.dismissMessageActions() },
onLinkPreviewClick: ((LinkPreview) -> Unit)? = null,
onCancelLinkPreviewClick: (() -> Unit)? = { viewModel.cancelLinkPreview() },
onUserSelected: (User) -> Unit = { viewModel.selectMention(it) },
onUserSelected: (User) -> Unit = {},
Comment thread
andremion marked this conversation as resolved.
onCommandSelected: (Command) -> Unit = viewModel::selectCommand,
onAlsoSendToChannelChange: (Boolean) -> Unit = viewModel::setAlsoSendToChannel,
onActiveCommandDismiss: () -> Unit = viewModel::clearActiveCommand,
recordingActions: AudioRecordingActions = AudioRecordingActions.defaultActions(
viewModel = viewModel,
sendOnComplete = ChatTheme.config.composer.audioRecordingSendOnComplete,
),
onMentionSelected: (Mention) -> Unit = viewModel::selectMention,
input: @Composable RowScope.(MessageComposerState) -> Unit = { state ->
val inputFocusRequester = remember { FocusRequester() }
LaunchedEffect(Unit) {
Expand Down Expand Up @@ -189,6 +197,7 @@
onSendMessage(messageWithData)
},
onUserSelected = onUserSelected,
onMentionSelected = onMentionSelected,
onCommandSelected = onCommandSelected,
onAlsoSendToChannelSelected = onAlsoSendToChannelChange,
onActiveCommandDismiss = onActiveCommandDismiss,
Expand Down Expand Up @@ -235,9 +244,16 @@
* @param onCancelAction Handler for the cancel button on Message actions, such as Edit and Reply.
* @param onLinkPreviewClick Handler when the user taps on a link preview.
* @param onCancelLinkPreviewClick Handler when the user taps on the cancel link preview.
* @param onUserSelected Handler when the user taps on a user suggestion item.
* @param onUserSelected Legacy handler that fires only when the user taps a user suggestion item.
* Kept for backward compatibility; new callers should use [onMentionSelected], which receives every
* mention type including users. Note both callbacks fire on a user tap: a custom [onUserSelected]
* runs in addition to [onMentionSelected], so the default [onMentionSelected] still inserts the
* mention. To replace the default selection behavior, override [onMentionSelected].
* @param onCommandSelected Handler when the user taps on a command suggestion item, including taps
* on disabled items.
* @param onMentionSelected Handler when the user taps any mention suggestion item. Canonical
* callback for all mention selections. Must be wired when any non-user mention kind is enabled —
* otherwise non-user mentions silently no-op on tap.
* @param onAlsoSendToChannelChange Handler when the "Also send to channel" checkbox is changed.
* @param onActiveCommandDismiss Called when the user taps the dismiss button on the active command chip.
* @param recordingActions The actions that can be performed on an audio recording.
Expand All @@ -264,6 +280,7 @@
onAlsoSendToChannelChange: (Boolean) -> Unit = {},
onActiveCommandDismiss: () -> Unit = {},
recordingActions: AudioRecordingActions = AudioRecordingActions.None,
onMentionSelected: (Mention) -> Unit = {},
input: @Composable RowScope.(MessageComposerState) -> Unit = { state ->
ChatTheme.componentFactory.MessageComposerInput(
params = MessageComposerInputParams(
Expand All @@ -285,7 +302,13 @@
},
) {
val validationErrors = messageComposerState.validationErrors
val userSuggestions = messageComposerState.mentionSuggestions
// Prefer the list with all mentions but fall back to the legacy user-only field for
// callers that construct MessageComposerState directly without going through the controller.
val suggestedMentions = messageComposerState.suggestedMentions
val legacyMentionSuggestions = messageComposerState.mentionSuggestions

Check warning on line 308 in stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/composer/MessageComposer.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Deprecated code should not be used.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-chat-android&issues=AZ7Vaz8kA0vd2wK0GTNM&open=AZ7Vaz8kA0vd2wK0GTNM&pullRequest=6503
val mentionSuggestions = remember(suggestedMentions, legacyMentionSuggestions) {
suggestedMentions.ifEmpty { legacyMentionSuggestions.map(Mention::User) }
}
val commandSuggestions = messageComposerState.commandSuggestions
val snackbarHostState = LocalMessageComposerSnackbarHostState.current ?: remember { SnackbarHostState() }

Expand All @@ -295,12 +318,13 @@
)

MessageComposerSurface(modifier = modifier) {
if (userSuggestions.isNotEmpty()) {
SuggestionsMenu(contentMaxHeight = UserSuggestionsMaxHeight) {
UserSuggestionList(
users = userSuggestions,
if (mentionSuggestions.isNotEmpty()) {
SuggestionsMenu(contentMaxHeight = MentionSuggestionsMaxHeight) {
MentionSuggestionList(
mentions = mentionSuggestions,
currentUser = messageComposerState.currentUser,
onUserSelected = onUserSelected,
onMentionSelected = onMentionSelected,
)
}
}
Expand Down Expand Up @@ -358,7 +382,7 @@
}
}

private val UserSuggestionsMaxHeight = 176.dp
private val MentionSuggestionsMaxHeight = 176.dp
private val CommandSuggestionsMaxHeight = 208.dp

@StringRes
Expand All @@ -368,18 +392,21 @@
is Reply -> R.string.stream_compose_message_composer_command_unavailable_in_reply
else -> null
}

is MessageComposerViewEvent.CancelCommandRequired -> when (action) {
is Edit -> R.string.stream_compose_message_composer_cancel_command_to_edit
is Reply -> R.string.stream_compose_message_composer_cancel_command_to_reply
else -> null
}

else -> null
}

private fun MessageComposerViewEvent.snackbarVariant(): StreamSnackbarVariant = when (this) {
is MessageComposerViewEvent.CommandUnavailable,
is MessageComposerViewEvent.CancelCommandRequired,
-> StreamSnackbarVariant.Error

else -> StreamSnackbarVariant.Default
}

Expand Down Expand Up @@ -516,6 +543,14 @@
PreviewUserData.user1,
PreviewUserData.user5,
),
suggestedMentions = listOf(
Mention.Channel,
Mention.Here,
Mention.User(PreviewUserData.userWithOnlineStatus),
Mention.User(PreviewUserData.user1),
Mention.User(PreviewUserData.user5),
Mention.Role("admin"),
),
),
onSendMessage = { _, _ -> },
)
Expand Down Expand Up @@ -622,6 +657,14 @@
PreviewUserData.user1,
PreviewUserData.user5,
),
suggestedMentions = listOf(
Mention.Channel,
Mention.Here,
Mention.User(PreviewUserData.userWithOnlineStatus),
Mention.User(PreviewUserData.user1),
Mention.User(PreviewUserData.user5),
Mention.Role("admin"),
),
),
onSendMessage = { _, _ -> },
)
Expand Down
Loading
Loading