Add support for sending images from the keyboard #1977
This commit is contained in:
1
changelog.d/1977.feature
Normal file
1
changelog.d/1977.feature
Normal file
@@ -0,0 +1 @@
|
||||
Add support for sending images from the keyboard
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.element.android.features.messages.impl.messagecomposer
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.compose.runtime.Immutable
|
||||
import io.element.android.features.messages.impl.mentions.MentionSuggestion
|
||||
import io.element.android.libraries.textcomposer.model.Message
|
||||
@@ -26,6 +27,7 @@ import io.element.android.libraries.textcomposer.model.Suggestion
|
||||
sealed interface MessageComposerEvents {
|
||||
data object ToggleFullScreenState : MessageComposerEvents
|
||||
data class SendMessage(val message: Message) : MessageComposerEvents
|
||||
data class SendUri(val uri: Uri) : MessageComposerEvents
|
||||
data object CloseSpecialMode : MessageComposerEvents
|
||||
data class SetMode(val composerMode: MessageComposerMode) : MessageComposerEvents
|
||||
data object AddAttachment : MessageComposerEvents
|
||||
|
||||
@@ -225,6 +225,18 @@ class MessageComposerPresenter @Inject constructor(
|
||||
updateComposerMode = { messageComposerContext.composerMode = it },
|
||||
richTextEditorState = richTextEditorState,
|
||||
)
|
||||
is MessageComposerEvents.SendUri -> appCoroutineScope.sendAttachment(
|
||||
attachment = Attachment.Media(
|
||||
localMedia = localMediaFactory.createFromUri(
|
||||
uri = event.uri,
|
||||
mimeType = null,
|
||||
name = null,
|
||||
formattedFileSize = null
|
||||
),
|
||||
compressIfPossible = true
|
||||
),
|
||||
attachmentState = attachmentsState,
|
||||
)
|
||||
is MessageComposerEvents.SetMode -> {
|
||||
messageComposerContext.composerMode = event.composerMode
|
||||
when (event.composerMode) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.element.android.features.messages.impl.messagecomposer
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.IntrinsicSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
@@ -52,6 +53,10 @@ internal fun MessageComposerView(
|
||||
state.eventSink(MessageComposerEvents.SendMessage(message))
|
||||
}
|
||||
|
||||
fun sendUri(uri: Uri) {
|
||||
state.eventSink(MessageComposerEvents.SendUri(uri))
|
||||
}
|
||||
|
||||
fun onAddAttachment() {
|
||||
state.eventSink(MessageComposerEvents.AddAttachment)
|
||||
}
|
||||
@@ -117,6 +122,7 @@ internal fun MessageComposerView(
|
||||
onSuggestionReceived = ::onSuggestionReceived,
|
||||
onError = ::onError,
|
||||
currentUserId = state.currentUserId,
|
||||
onRichContentSelected = ::sendUri,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.element.android.libraries.textcomposer
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
@@ -111,6 +112,7 @@ fun TextComposer(
|
||||
onDeleteVoiceMessage: () -> Unit,
|
||||
onError: (Throwable) -> Unit,
|
||||
onSuggestionReceived: (Suggestion?) -> Unit,
|
||||
onRichContentSelected: ((Uri) -> Unit)?,
|
||||
modifier: Modifier = Modifier,
|
||||
showTextFormatting: Boolean = false,
|
||||
subcomposing: Boolean = false,
|
||||
@@ -162,6 +164,7 @@ fun TextComposer(
|
||||
resolveMentionDisplay = { text, url -> TextDisplay.Custom(mentionSpanProvider.getMentionSpanFor(text, url)) },
|
||||
resolveRoomMentionDisplay = { TextDisplay.Custom(mentionSpanProvider.getMentionSpanFor("@room", "#")) },
|
||||
onError = onError,
|
||||
onRichContentSelected = onRichContentSelected,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -397,6 +400,7 @@ private fun TextInput(
|
||||
resolveMentionDisplay: (text: String, url: String) -> TextDisplay,
|
||||
modifier: Modifier = Modifier,
|
||||
onError: (Throwable) -> Unit = {},
|
||||
onRichContentSelected: ((Uri) -> Unit)? = null,
|
||||
) {
|
||||
val bgColor = ElementTheme.colors.bgSubtleSecondary
|
||||
val borderColor = ElementTheme.colors.borderDisabled
|
||||
@@ -443,7 +447,8 @@ private fun TextInput(
|
||||
style = ElementRichTextEditorStyle.composerStyle(hasFocus = state.hasFocus),
|
||||
resolveMentionDisplay = resolveMentionDisplay,
|
||||
resolveRoomMentionDisplay = resolveRoomMentionDisplay,
|
||||
onError = onError
|
||||
onError = onError,
|
||||
onRichContentSelected = onRichContentSelected,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -902,5 +907,6 @@ private fun ATextComposer(
|
||||
onDeleteVoiceMessage = {},
|
||||
onError = {},
|
||||
onSuggestionReceived = {},
|
||||
onRichContentSelected = null,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user