Skip to content
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

fix: Draft message issue #WPB-11565 #3515

Merged
merged 6 commits into from
Oct 22, 2024
Merged
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 @@ -235,6 +235,7 @@ fun ConversationScreen(
val messageComposerStateHolder = rememberMessageComposerStateHolder(
messageComposerViewState = messageComposerViewState,
draftMessageComposition = messageDraftViewModel.state.value,
onClearDraft = messageDraftViewModel::clearDraft,
onSaveDraft = messageComposerViewModel::saveDraft,
onSearchMentionQueryChanged = messageComposerViewModel::searchMembersToMention,
onTypingEvent = messageComposerViewModel::sendTypingEvent,
Expand Down Expand Up @@ -1366,6 +1367,7 @@ fun PreviewConversationScreen() = WireTheme {
val messageComposerStateHolder = rememberMessageComposerStateHolder(
messageComposerViewState = messageComposerViewState,
draftMessageComposition = messageCompositionState.value,
onClearDraft = {},
onSaveDraft = {},
onTypingEvent = {},
onSearchMentionQueryChanged = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class MessageDraftViewModel @Inject constructor(
loadMessageDraft()
}

fun clearDraft() {
viewModelScope.launch {
state.update {
MessageComposition(conversationId, String.EMPTY)
}
}
}

private fun loadMessageDraft() {
viewModelScope.launch {
val draftResult = getMessageDraft(conversationId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ fun MessageComposer(
onSendMessageBundle(messageCompositionHolder.toMessageBundle(conversationId))
onClearMentionSearchResult()
clearMessage()
messageCompositionHolder.onClearDraft()
},
onPingOptionClicked = onPingOptionClicked,
onImagesPicked = onImagesPicked,
Expand Down Expand Up @@ -265,6 +266,7 @@ private fun BaseComposerPreview(
messageCompositionHolder = MessageCompositionHolder(
messageComposition = messageComposition,
messageTextState = messageTextState,
onClearDraft = {},
onSaveDraft = {},
onSearchMentionQueryChanged = {},
onClearMentionSearchResult = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.wire.kalium.logic.data.message.mention.MessageMention
fun rememberMessageComposerStateHolder(
messageComposerViewState: State<MessageComposerViewState>,
draftMessageComposition: MessageComposition,
onClearDraft: () -> Unit,
onSaveDraft: (MessageDraft) -> Unit,
onSearchMentionQueryChanged: (String) -> Unit,
onClearMentionSearchResult: () -> Unit,
Expand All @@ -62,6 +63,7 @@ fun rememberMessageComposerStateHolder(
MessageCompositionHolder(
messageComposition = messageComposition,
messageTextState = messageTextState,
onClearDraft = onClearDraft,
onSaveDraft = onSaveDraft,
onSearchMentionQueryChanged = onSearchMentionQueryChanged,
onClearMentionSearchResult = onClearMentionSearchResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
class MessageCompositionHolder(
val messageComposition: MutableState<MessageComposition>,
val messageTextState: TextFieldState,
val onClearDraft: () -> Unit,
private val onSaveDraft: (MessageDraft) -> Unit,
private val onSearchMentionQueryChanged: (String) -> Unit,
private val onClearMentionSearchResult: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class MessageComposerStateHolderTest {
messageCompositionHolder = MessageCompositionHolder(
messageComposition = messageComposition,
messageTextState = messageTextState,
onClearDraft = {},
onSaveDraft = {},
onSearchMentionQueryChanged = {},
onClearMentionSearchResult = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class MessageCompositionHolderTest {
state = MessageCompositionHolder(
messageComposition = messageComposition,
messageTextState = messageTextState,
onClearDraft = {},
onSaveDraft = {},
onSearchMentionQueryChanged = {},
onClearMentionSearchResult = {},
Expand Down
Loading