-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat: composite messages #1997
feat: composite messages #1997
Changes from 12 commits
1a8301a
90a82e4
68fcdc1
acd9b3d
c1700cb
1f2d33f
e740bb3
06538ba
32ff217
e965629
3512a0e
5ee271b
be434e6
9814609
8916ff8
dc058d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,10 +247,20 @@ fun MessagePreview.uiLastMessageContent(): UILastMessageContent { | |
is WithUser.TeamMemberRemoved -> UILastMessageContent.None // TODO | ||
is WithUser.Text -> UILastMessageContent.SenderWithMessage( | ||
sender = userUIText, | ||
message = UIText.DynamicString((content as WithUser.Text).messageBody), | ||
message = (content as WithUser.Text).messageBody.let { UIText.DynamicString(it) }, | ||
separator = ": " | ||
) | ||
|
||
is WithUser.Composite -> { | ||
val text = (content as WithUser.Composite).messageBody?.let { UIText.DynamicString(it) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn;t this crash prone when content is not WithUser.Composite and we try to cast it ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is impossible to crash this because of the |
||
?: UIText.StringResource(R.string.last_message_composite_with_missing_text) | ||
UILastMessageContent.SenderWithMessage( | ||
sender = userUIText, | ||
message = text, | ||
separator = ": " | ||
) | ||
} | ||
|
||
is WithUser.MissedCall -> UILastMessageContent.TextMessage( | ||
MessageBody(UIText.PluralResource(R.plurals.unread_event_call, 1, 1)) | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import com.wire.android.model.ImageAsset | |
import com.wire.android.ui.home.conversations.findUser | ||
import com.wire.android.ui.home.conversations.model.DeliveryStatusContent | ||
import com.wire.android.ui.home.conversations.model.MessageBody | ||
import com.wire.android.ui.home.conversations.model.MessageButton | ||
import com.wire.android.ui.home.conversations.model.UIMessageContent | ||
import com.wire.android.ui.home.conversations.model.UIQuotedMessage | ||
import com.wire.android.util.time.ISOFormatter | ||
|
@@ -91,6 +92,33 @@ class RegularMessageMapper @Inject constructor( | |
message.deliveryStatus | ||
) | ||
|
||
is MessageContent.Composite -> { | ||
val text = content.textContent?.let { textContent -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can;t we map it inside the mapper ? |
||
val quotedMessage = textContent.quotedMessageDetails?.let { mapQuoteData(message.conversationId, it) } | ||
?: if (textContent.quotedMessageReference?.quotedMessageId != null) { | ||
UIQuotedMessage.UnavailableData | ||
} else { | ||
null | ||
} | ||
|
||
MessageBody( | ||
message = UIText.DynamicString(textContent.value, content.textContent?.mentions.orEmpty()), | ||
quotedMessage = quotedMessage | ||
) | ||
} | ||
|
||
UIMessageContent.Composite( | ||
messageBody = text, | ||
buttonList = content.buttonList.map { | ||
MessageButton( | ||
id = it.id, | ||
text = it.text, | ||
isSelected = it.isSelected | ||
) | ||
} | ||
) | ||
} | ||
|
||
else -> toText(message.conversationId, content, userList, message.deliveryStatus) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.ui.home.conversations | ||
|
||
import androidx.annotation.VisibleForTesting | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.wire.android.navigation.EXTRA_CONVERSATION_ID | ||
import com.wire.android.navigation.EXTRA_MESSAGE_ID | ||
import com.wire.kalium.logic.data.id.MessageButtonId | ||
import com.wire.kalium.logic.data.id.QualifiedID | ||
import com.wire.kalium.logic.data.id.QualifiedIdMapper | ||
import com.wire.kalium.logic.feature.message.composite.SendButtonActionMessageUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class CompositeMessageViewModel @Inject constructor( | ||
private val sendButtonActionMessageUseCase: SendButtonActionMessageUseCase, | ||
qualifiedIdMapper: QualifiedIdMapper, | ||
savedStateHandle: SavedStateHandle, | ||
) : ViewModel() { | ||
|
||
val conversationId: QualifiedID = qualifiedIdMapper.fromStringToQualifiedID( | ||
savedStateHandle.get<String>(EXTRA_CONVERSATION_ID)!! | ||
) | ||
|
||
private val messageId: String = savedStateHandle.get<String>(EXTRA_MESSAGE_ID)!! | ||
|
||
var pendingButtonId: MessageButtonId? by mutableStateOf(null) | ||
@VisibleForTesting | ||
set | ||
|
||
fun sendButtonActionMessage(buttonId: String) { | ||
if (pendingButtonId != null) return | ||
|
||
pendingButtonId = buttonId | ||
viewModelScope.launch { | ||
sendButtonActionMessageUseCase(conversationId, messageId, buttonId) | ||
}.invokeOnCompletion { | ||
pendingButtonId = null | ||
} | ||
} | ||
|
||
companion object { | ||
const val ARGS_KEY = "CompositeMessageViewModelKey" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this crash prone ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, since this code will only be executed when the content is Text