-
Notifications
You must be signed in to change notification settings - Fork 303
Ensure MessageComposer
respects the send-
capabilities
#5973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
VelikovPetar
wants to merge
5
commits into
develop
Choose a base branch
from
bug/AND-859-ensure-composer-respects-send-capabilities
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ac4392a
Ensure the message composer respects the `send-` capabilities.
VelikovPetar 61d210f
Ensure the message composer respects the `send-` capabilities.
VelikovPetar 0bf0c49
Ensure the message composer respects the `send-` capabilities.
VelikovPetar 212582e
Update CHANGELOG.md.
VelikovPetar d624395
Merge branch 'develop' into bug/AND-859-ensure-composer-respects-send…
VelikovPetar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
63 changes: 63 additions & 0 deletions
63
...t/android/ui/common/feature/messages/composer/capabilities/MessageComposerCapabilities.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved. | ||
* | ||
* Licensed under the Stream License; | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.getstream.chat.android.ui.common.feature.messages.composer.capabilities | ||
|
||
import io.getstream.chat.android.models.ChannelCapabilities | ||
import io.getstream.chat.android.ui.common.state.messages.MessageMode | ||
import io.getstream.chat.android.ui.common.state.messages.composer.MessageComposerState | ||
|
||
/** | ||
* Determines whether the user can send a message in the current state. | ||
* | ||
* This function checks both channel-level capabilities and user preferences to determine | ||
* if a message can be sent. The required capability depends on the current message mode: | ||
* - In thread mode: requires [ChannelCapabilities.SEND_REPLY] capability | ||
* - In regular mode: requires [ChannelCapabilities.SEND_MESSAGE] capability | ||
* | ||
* The final decision also considers the [MessageComposerState.sendEnabled] flag, which allows | ||
* temporary disabling of sending (e.g., while uploading attachments or validating input). | ||
* | ||
* @param state The current [MessageComposerState] containing capability and mode information. | ||
* @return `true` if the user can send a message or reply based on both capabilities and | ||
* the send enabled flag; `false` otherwise. | ||
*/ | ||
public fun canSendMessage(state: MessageComposerState): Boolean { | ||
val canSendMessage = state.ownCapabilities.contains(ChannelCapabilities.SEND_MESSAGE) | ||
val canSendReply = state.ownCapabilities.contains(ChannelCapabilities.SEND_REPLY) | ||
val isInThread = state.messageMode is MessageMode.MessageThread | ||
val canSend = if (isInThread) { | ||
canSendReply | ||
} else { | ||
canSendMessage | ||
} | ||
// The final send capability depends on the channel capabilities, and potentially the user-set sendEnabled flag | ||
return state.sendEnabled && canSend | ||
} | ||
|
||
/** | ||
* Determines whether the user can upload files in the current state. | ||
* | ||
* This function checks if the user has the [ChannelCapabilities.UPLOAD_FILE] capability | ||
* for the current channel. This capability allows users to attach and upload files | ||
* (documents, images, videos, etc.) through the message composer. | ||
* | ||
* @param state The current [MessageComposerState] containing capability information. | ||
* @return `true` if the user has the [ChannelCapabilities.UPLOAD_FILE] capability; `false` otherwise. | ||
*/ | ||
public fun canUploadFile(state: MessageComposerState): Boolean { | ||
return state.ownCapabilities.contains(ChannelCapabilities.UPLOAD_FILE) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.