diff --git a/app/src/main/java/tech/relaycorp/letro/di/ConversationsModule.kt b/app/src/main/java/tech/relaycorp/letro/di/ConversationsModule.kt index e86e5d80..581e8a06 100644 --- a/app/src/main/java/tech/relaycorp/letro/di/ConversationsModule.kt +++ b/app/src/main/java/tech/relaycorp/letro/di/ConversationsModule.kt @@ -13,8 +13,8 @@ import tech.relaycorp.letro.messages.parser.NewConversationMessageParser import tech.relaycorp.letro.messages.parser.NewConversationMessageParserImpl import tech.relaycorp.letro.messages.parser.NewMessageMessageParser import tech.relaycorp.letro.messages.parser.NewMessageMessageParserImpl -import tech.relaycorp.letro.messages.parser.OutgoingConversationMessageEncoder -import tech.relaycorp.letro.messages.parser.OutgoingConversationMessageEncoderImpl +import tech.relaycorp.letro.messages.parser.OutgoingMessageMessageEncoder +import tech.relaycorp.letro.messages.parser.OutgoingMessageMessageEncoderImpl import tech.relaycorp.letro.messages.processor.NewConversationProcessor import tech.relaycorp.letro.messages.processor.NewConversationProcessorImpl import tech.relaycorp.letro.messages.processor.NewMessageProcessor @@ -62,8 +62,8 @@ object ConversationsModule { @Binds fun bindOutgoingConversationMessageEncoder( - impl: OutgoingConversationMessageEncoderImpl, - ): OutgoingConversationMessageEncoder + impl: OutgoingMessageMessageEncoderImpl, + ): OutgoingMessageMessageEncoder @Binds fun bindNewConversationProcessor( diff --git a/app/src/main/java/tech/relaycorp/letro/home/HomeViewModel.kt b/app/src/main/java/tech/relaycorp/letro/home/HomeViewModel.kt index 316c499d..8df7b6f7 100644 --- a/app/src/main/java/tech/relaycorp/letro/home/HomeViewModel.kt +++ b/app/src/main/java/tech/relaycorp/letro/home/HomeViewModel.kt @@ -22,9 +22,9 @@ class HomeViewModel @Inject constructor( val uiState: StateFlow get() = _uiState - private val _createNewMessageSignal: MutableSharedFlow = MutableSharedFlow() - val createNewMessageSignal: SharedFlow - get() = _createNewMessageSignal + private val _createNewConversationSignal: MutableSharedFlow = MutableSharedFlow() + val createNewConversationSignal: SharedFlow + get() = _createNewConversationSignal init { viewModelScope.launch { @@ -59,7 +59,7 @@ class HomeViewModel @Inject constructor( viewModelScope.launch { when (uiState.value.currentTab) { TAB_CHATS -> { - _createNewMessageSignal.emit(Unit) + _createNewConversationSignal.emit(Unit) } TAB_CONTACTS -> { _uiState.update { diff --git a/app/src/main/java/tech/relaycorp/letro/messages/compose/ComposeNewMessageScreen.kt b/app/src/main/java/tech/relaycorp/letro/messages/compose/ComposeNewMessageScreen.kt index 16c14bf0..81399d24 100644 --- a/app/src/main/java/tech/relaycorp/letro/messages/compose/ComposeNewMessageScreen.kt +++ b/app/src/main/java/tech/relaycorp/letro/messages/compose/ComposeNewMessageScreen.kt @@ -46,9 +46,12 @@ import tech.relaycorp.letro.ui.common.LetroButton import tech.relaycorp.letro.ui.common.LetroTextField import tech.relaycorp.letro.ui.theme.HorizontalScreenPadding import tech.relaycorp.letro.ui.theme.LetroColor +import tech.relaycorp.letro.ui.utils.ConversationsStringsProvider +import tech.relaycorp.letro.utils.ext.applyIf @Composable fun CreateNewMessageScreen( + conversationsStringsProvider: ConversationsStringsProvider, onBackClicked: () -> Unit, onMessageSent: () -> Unit, viewModel: CreateNewMessageViewModel = hiltViewModel(), @@ -138,12 +141,16 @@ fun CreateNewMessageScreen( Text( text = stringResource(id = R.string.new_message_from), style = MaterialTheme.typography.bodyLarge, - color = MaterialTheme.colorScheme.onSurfaceVariant, + color = MaterialTheme.colorScheme.onSurfaceVariant + .applyIf(uiState.isOnlyTextEditale) { + copy(alpha = 0.38f) + }, ) Spacer(modifier = Modifier.width(16.dp)) Text( text = uiState.sender, - color = MaterialTheme.colorScheme.onSurface, + color = MaterialTheme.colorScheme.onSurface + .copy(alpha = 0.38F), style = MaterialTheme.typography.bodyLarge, ) } @@ -158,7 +165,10 @@ fun CreateNewMessageScreen( Text( text = stringResource(id = R.string.new_message_to), style = MaterialTheme.typography.bodyLarge, - color = MaterialTheme.colorScheme.onSurfaceVariant, + color = MaterialTheme.colorScheme.onSurfaceVariant + .applyIf(uiState.isOnlyTextEditale) { + copy(alpha = 0.38f) + }, ) if (uiState.showRecipientAsChip) { Spacer(modifier = Modifier.width(16.dp)) @@ -171,6 +181,7 @@ fun CreateNewMessageScreen( viewModel.onRecipientRemoveClick() recipientTextFieldValueState = TextFieldValue() }, + isEditable = !uiState.isOnlyTextEditale, ) Spacer(modifier = Modifier.height(TextFieldDefaults.MinHeight)) } @@ -214,20 +225,38 @@ fun CreateNewMessageScreen( } else -> { Column { - LetroTextField( - value = subjectTextFieldValueState, - onValueChange = { - subjectTextFieldValueState = it - viewModel.onSubjectTextChanged(it.text) - }, - placeHolderText = stringResource(id = R.string.new_message_subject_hint), - keyboardOptions = KeyboardOptions.Default.copy( - imeAction = ImeAction.Next, - ), - placeholderColor = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier - .onFocusChanged { viewModel.onSubjectTextFieldFocused(it.isFocused) }, - ) + if (!uiState.isOnlyTextEditale) { + LetroTextField( + value = subjectTextFieldValueState, + onValueChange = { + subjectTextFieldValueState = it + viewModel.onSubjectTextChanged(it.text) + }, + placeHolderText = stringResource(id = R.string.new_message_subject_hint), + keyboardOptions = KeyboardOptions.Default.copy( + imeAction = ImeAction.Next, + ), + placeholderColor = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier + .onFocusChanged { viewModel.onSubjectTextFieldFocused(it.isFocused) }, + ) + } else { + Box( + modifier = Modifier + .height(TextFieldDefaults.MinHeight) + .padding(horizontal = 16.dp), + ) { + Text( + text = if (uiState.showNoSubjectText) conversationsStringsProvider.noSubject else uiState.subject, + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurface + .copy(alpha = 0.38F), + maxLines = 1, + modifier = Modifier + .align(Alignment.CenterStart), + ) + } + } Divider() LetroTextField( value = messageTextFieldValueState, @@ -277,13 +306,14 @@ private fun SuggestContactsList( private fun RecipientChipView( text: String, onRemoveClick: () -> Unit, + isEditable: Boolean, modifier: Modifier = Modifier, ) { Row( verticalAlignment = Alignment.CenterVertically, modifier = modifier .background( - color = MaterialTheme.colorScheme.surfaceVariant, + color = if (isEditable) MaterialTheme.colorScheme.surfaceVariant else MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.06F), shape = RoundedCornerShape(80.dp), ) .padding( @@ -294,15 +324,20 @@ private fun RecipientChipView( Text( text = text, style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurface, - ) - Spacer(modifier = Modifier.width(8.dp)) - Icon( - painter = painterResource(id = R.drawable.ic_chip_delete), - contentDescription = stringResource(id = R.string.content_description_recipient_clear), - tint = LetroColor.OnSurfaceContainer, - modifier = Modifier - .clickable { onRemoveClick() }, + color = MaterialTheme.colorScheme.onSurface + .applyIf(!isEditable) { + copy(alpha = 0.3F) + }, ) + if (isEditable) { + Spacer(modifier = Modifier.width(8.dp)) + Icon( + painter = painterResource(id = R.drawable.ic_chip_delete), + contentDescription = stringResource(id = R.string.content_description_recipient_clear), + tint = LetroColor.OnSurfaceContainer, + modifier = Modifier + .clickable { onRemoveClick() }, + ) + } } } diff --git a/app/src/main/java/tech/relaycorp/letro/messages/compose/ComposeNewMessageViewModel.kt b/app/src/main/java/tech/relaycorp/letro/messages/compose/ComposeNewMessageViewModel.kt index d7a61416..265a8fe2 100644 --- a/app/src/main/java/tech/relaycorp/letro/messages/compose/ComposeNewMessageViewModel.kt +++ b/app/src/main/java/tech/relaycorp/letro/messages/compose/ComposeNewMessageViewModel.kt @@ -1,5 +1,7 @@ package tech.relaycorp.letro.messages.compose +import androidx.annotation.IntDef +import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel @@ -13,7 +15,11 @@ import tech.relaycorp.letro.account.storage.AccountRepository import tech.relaycorp.letro.contacts.model.Contact import tech.relaycorp.letro.contacts.model.ContactPairingStatus import tech.relaycorp.letro.contacts.storage.ContactsRepository +import tech.relaycorp.letro.messages.compose.CreateNewMessageViewModel.ScreenType.Companion.NEW_CONVERSATION +import tech.relaycorp.letro.messages.compose.CreateNewMessageViewModel.ScreenType.Companion.REPLY_TO_EXISTING_CONVERSATION +import tech.relaycorp.letro.messages.model.ExtendedConversation import tech.relaycorp.letro.messages.repository.ConversationsRepository +import tech.relaycorp.letro.ui.navigation.Route import tech.relaycorp.letro.utils.ext.emitOn import tech.relaycorp.letro.utils.ext.isEmptyOrBlank import tech.relaycorp.letro.utils.ext.isNotEmptyOrBlank @@ -24,9 +30,25 @@ class CreateNewMessageViewModel @Inject constructor( private val accountRepository: AccountRepository, private val contactsRepository: ContactsRepository, private val conversationsRepository: ConversationsRepository, + private val savedStateHandle: SavedStateHandle, ) : ViewModel() { - private val _uiState = MutableStateFlow(NewMessageUiState()) + @ScreenType + private val screenType: Int = savedStateHandle[Route.CreateNewMessage.KEY_SCREEN_TYPE]!! + private val conversation: ExtendedConversation? = + (savedStateHandle.get(Route.CreateNewMessage.KEY_CONVERSATION_ID) as? String) + ?.let { conversationsRepository.getConversation(it) } + + private val _uiState = MutableStateFlow( + NewMessageUiState( + sender = conversation?.ownerVeraId ?: "", + recipient = conversation?.contactDisplayName ?: "", + subject = conversation?.subject ?: "", + showNoSubjectText = conversation != null && conversation.subject.isNullOrEmpty(), + showRecipientAsChip = conversation != null, + isOnlyTextEditale = conversation != null, + ), + ) val uiState: StateFlow get() = _uiState @@ -133,12 +155,26 @@ class CreateNewMessageViewModel @Inject constructor( fun onSendMessageClick() { val contact = contacts.find { it.contactVeraId == uiState.value.recipient } ?: return - conversationsRepository.createNewConversation( - ownerVeraId = uiState.value.sender, - recipient = contact, - messageText = uiState.value.messageText, - subject = uiState.value.subject, - ) + when (screenType) { + NEW_CONVERSATION -> { + conversationsRepository.createNewConversation( + ownerVeraId = uiState.value.sender, + recipient = contact, + messageText = uiState.value.messageText, + subject = uiState.value.subject, + ) + } + REPLY_TO_EXISTING_CONVERSATION -> { + val conversation = conversation ?: return + conversationsRepository.reply( + conversationId = conversation.conversationId, + messageText = uiState.value.messageText, + ) + } + else -> { + throw IllegalStateException("Unknown screen type $screenType!") + } + } _messageSentSignal.emitOn(Unit, viewModelScope) } @@ -171,6 +207,14 @@ class CreateNewMessageViewModel @Inject constructor( ): Boolean { return contacts.any { recipient == it.contactVeraId } && messageText.isNotEmptyOrBlank() } + + @IntDef(NEW_CONVERSATION, REPLY_TO_EXISTING_CONVERSATION) + annotation class ScreenType { + companion object { + const val NEW_CONVERSATION = 0 + const val REPLY_TO_EXISTING_CONVERSATION = 1 + } + } } data class NewMessageUiState( @@ -181,5 +225,7 @@ data class NewMessageUiState( val showRecipientIsNotYourContactError: Boolean = false, val isSendButtonEnabled: Boolean = false, val showRecipientAsChip: Boolean = false, + val isOnlyTextEditale: Boolean = false, + val showNoSubjectText: Boolean = false, val suggestedContacts: List? = null, ) diff --git a/app/src/main/java/tech/relaycorp/letro/messages/parser/NewConversationMessageParser.kt b/app/src/main/java/tech/relaycorp/letro/messages/parser/NewConversationMessageParser.kt index b29619c1..fe1ce1ec 100644 --- a/app/src/main/java/tech/relaycorp/letro/messages/parser/NewConversationMessageParser.kt +++ b/app/src/main/java/tech/relaycorp/letro/messages/parser/NewConversationMessageParser.kt @@ -13,7 +13,7 @@ class NewConversationMessageParserImpl @Inject constructor() : NewConversationMe override fun parse(content: ByteArray): NewConversationIncomingMessage { val conversation = mockConversation() // TODO: parse conversation - val message = mockMessage(conversation.conversationId) + val message = mockMessage(conversation.conversationId) // TODO: create message object return NewConversationIncomingMessage( content = NewConversationIncomingMessageContent( conversation = conversation, diff --git a/app/src/main/java/tech/relaycorp/letro/messages/parser/OutgoingConversationMessageEncoder.kt b/app/src/main/java/tech/relaycorp/letro/messages/parser/OutgoingConversationMessageEncoder.kt deleted file mode 100644 index 96566eed..00000000 --- a/app/src/main/java/tech/relaycorp/letro/messages/parser/OutgoingConversationMessageEncoder.kt +++ /dev/null @@ -1,15 +0,0 @@ -package tech.relaycorp.letro.messages.parser - -import tech.relaycorp.letro.messages.storage.entity.Conversation -import javax.inject.Inject - -interface OutgoingConversationMessageEncoder { - fun encode(conversation: Conversation): ByteArray -} - -class OutgoingConversationMessageEncoderImpl @Inject constructor() : OutgoingConversationMessageEncoder { - - override fun encode(conversation: Conversation): ByteArray { - return ByteArray(0) // TODO: encode conversation to ByteArray - } -} diff --git a/app/src/main/java/tech/relaycorp/letro/messages/parser/OutgoingMessageMessageEncoder.kt b/app/src/main/java/tech/relaycorp/letro/messages/parser/OutgoingMessageMessageEncoder.kt new file mode 100644 index 00000000..65bf173c --- /dev/null +++ b/app/src/main/java/tech/relaycorp/letro/messages/parser/OutgoingMessageMessageEncoder.kt @@ -0,0 +1,21 @@ +package tech.relaycorp.letro.messages.parser + +import tech.relaycorp.letro.messages.storage.entity.Conversation +import tech.relaycorp.letro.messages.storage.entity.Message +import javax.inject.Inject + +interface OutgoingMessageMessageEncoder { + fun encodeNewConversationContent(conversation: Conversation): ByteArray + fun encodeNewMessageContent(message: Message): ByteArray +} + +class OutgoingMessageMessageEncoderImpl @Inject constructor() : OutgoingMessageMessageEncoder { + + override fun encodeNewConversationContent(conversation: Conversation): ByteArray { + return ByteArray(0) // TODO: encode conversation to ByteArray + } + + override fun encodeNewMessageContent(message: Message): ByteArray { + return ByteArray(0) // TODO: encode message to ByteArray + } +} diff --git a/app/src/main/java/tech/relaycorp/letro/messages/repository/ConversationsRepository.kt b/app/src/main/java/tech/relaycorp/letro/messages/repository/ConversationsRepository.kt index add3540f..d38cccd8 100644 --- a/app/src/main/java/tech/relaycorp/letro/messages/repository/ConversationsRepository.kt +++ b/app/src/main/java/tech/relaycorp/letro/messages/repository/ConversationsRepository.kt @@ -18,7 +18,7 @@ import tech.relaycorp.letro.contacts.model.Contact import tech.relaycorp.letro.contacts.storage.ContactsRepository import tech.relaycorp.letro.messages.converter.ExtendedConversationConverter import tech.relaycorp.letro.messages.model.ExtendedConversation -import tech.relaycorp.letro.messages.parser.OutgoingConversationMessageEncoder +import tech.relaycorp.letro.messages.parser.OutgoingMessageMessageEncoder import tech.relaycorp.letro.messages.storage.ConversationsDao import tech.relaycorp.letro.messages.storage.MessagesDao import tech.relaycorp.letro.messages.storage.entity.Conversation @@ -35,6 +35,10 @@ interface ConversationsRepository { messageText: String, subject: String? = null, ) + fun reply( + conversationId: UUID, + messageText: String, + ) fun getConversation(id: String): ExtendedConversation? fun markConversationAsRead(conversationId: String) fun deleteConversation(conversationId: String) @@ -47,7 +51,7 @@ class ConversationsRepositoryImpl @Inject constructor( private val accountRepository: AccountRepository, private val conversationsConverter: ExtendedConversationConverter, private val awalaManager: AwalaManager, - private val outgoingConversationMessageEncoder: OutgoingConversationMessageEncoder, + private val outgoingMessageMessageEncoder: OutgoingMessageMessageEncoder, ) : ConversationsRepository { private val scope = CoroutineScope(Dispatchers.IO) @@ -113,7 +117,35 @@ class ConversationsRepositoryImpl @Inject constructor( awalaManager.sendMessage( outgoingMessage = AwalaOutgoingMessage( type = MessageType.NewConversation, - content = outgoingConversationMessageEncoder.encode(conversation), + content = outgoingMessageMessageEncoder.encodeNewConversationContent(conversation), + ), + recipient = MessageRecipient.User( + nodeId = recipientNodeId, + ), + ) + } + } + + override fun reply(conversationId: UUID, messageText: String) { + scope.launch { + val conversation = _conversations.value + .find { it.conversationId == conversationId } ?: return@launch + val recipientNodeId = contacts.value + .find { it.contactVeraId == conversation.contactVeraId && it.ownerVeraId == conversation.ownerVeraId } + ?.contactEndpointId ?: return@launch + val message = Message( + conversationId = conversationId, + text = messageText, + ownerVeraId = conversation.ownerVeraId, + senderVeraId = conversation.ownerVeraId, + recipientVeraId = conversation.contactVeraId, + sentAt = LocalDateTime.now(), + ) + messagesDao.insert(message) + awalaManager.sendMessage( + outgoingMessage = AwalaOutgoingMessage( + type = MessageType.NewMessage, + content = outgoingMessageMessageEncoder.encodeNewMessageContent(message), ), recipient = MessageRecipient.User( nodeId = recipientNodeId, diff --git a/app/src/main/java/tech/relaycorp/letro/messages/viewing/ConversationScreen.kt b/app/src/main/java/tech/relaycorp/letro/messages/viewing/ConversationScreen.kt index 10ad66dc..eecbfb45 100644 --- a/app/src/main/java/tech/relaycorp/letro/messages/viewing/ConversationScreen.kt +++ b/app/src/main/java/tech/relaycorp/letro/messages/viewing/ConversationScreen.kt @@ -44,6 +44,7 @@ import tech.relaycorp.letro.utils.ext.applyIf @Composable fun ConversationScreen( conversationsStringsProvider: ConversationsStringsProvider, + onReplyClick: () -> Unit, onConversationDeleted: () -> Unit, onBackClicked: () -> Unit, viewModel: ConversationViewModel = hiltViewModel(), @@ -74,6 +75,7 @@ fun ConversationScreen( } Column { ConversationToolbar( + onReplyClick = onReplyClick, onBackClicked = onBackClicked, onDeleteClick = { viewModel.onDeleteConversationClick() }, ) @@ -173,6 +175,7 @@ private fun Message( @Composable private fun ConversationToolbar( + onReplyClick: () -> Unit, onDeleteClick: () -> Unit, onBackClicked: () -> Unit, ) { @@ -207,7 +210,7 @@ private fun ConversationToolbar( } LetroButton( text = stringResource(id = R.string.reply), - onClick = { /* TODO */ }, + onClick = onReplyClick, leadingIconResId = R.drawable.ic_reply, contentPadding = PaddingValues( top = 8.dp, diff --git a/app/src/main/java/tech/relaycorp/letro/ui/navigation/LetroNavHost.kt b/app/src/main/java/tech/relaycorp/letro/ui/navigation/LetroNavHost.kt index f1d78707..499dbfbb 100644 --- a/app/src/main/java/tech/relaycorp/letro/ui/navigation/LetroNavHost.kt +++ b/app/src/main/java/tech/relaycorp/letro/ui/navigation/LetroNavHost.kt @@ -41,6 +41,7 @@ import tech.relaycorp.letro.home.HomeScreen import tech.relaycorp.letro.home.HomeViewModel import tech.relaycorp.letro.main.MainViewModel import tech.relaycorp.letro.messages.compose.CreateNewMessageScreen +import tech.relaycorp.letro.messages.compose.CreateNewMessageViewModel import tech.relaycorp.letro.messages.viewing.ConversationScreen import tech.relaycorp.letro.onboarding.actionTaking.ActionTakingScreen import tech.relaycorp.letro.onboarding.actionTaking.ActionTakingScreenUIStateModel @@ -94,8 +95,8 @@ fun LetroNavHost( } LaunchedEffect(Unit) { - homeViewModel.createNewMessageSignal.collect { - navController.navigate(Route.CreateNewMessage.name) + homeViewModel.createNewConversationSignal.collect { + navController.navigate(Route.CreateNewMessage.getRouteName(CreateNewMessageViewModel.ScreenType.NEW_CONVERSATION)) } } @@ -238,11 +239,38 @@ fun LetroNavHost( }, ) } - composable(Route.CreateNewMessage.name) { + composable( + route = "${Route.CreateNewMessage.name}" + + "?${Route.CreateNewMessage.KEY_SCREEN_TYPE}={${Route.CreateNewMessage.KEY_SCREEN_TYPE}}" + + "&${Route.CreateNewMessage.KEY_CONVERSATION_ID}={${Route.CreateNewMessage.KEY_CONVERSATION_ID}}", + arguments = listOf( + navArgument(Route.CreateNewMessage.KEY_SCREEN_TYPE) { + type = NavType.IntType + nullable = false + }, + navArgument(Route.CreateNewMessage.KEY_CONVERSATION_ID) { + type = NavType.StringType + nullable = true + defaultValue = null + }, + ), + ) { + val screenType = it.arguments?.getInt(Route.CreateNewMessage.KEY_SCREEN_TYPE) CreateNewMessageScreen( + conversationsStringsProvider = stringsProvider.conversations, onBackClicked = { navController.popBackStack() }, onMessageSent = { - navController.popBackStack() + when (screenType) { + CreateNewMessageViewModel.ScreenType.REPLY_TO_EXISTING_CONVERSATION -> { + navController.popBackStack( + route = Route.Home.name, + inclusive = false, + ) + } + CreateNewMessageViewModel.ScreenType.NEW_CONVERSATION -> { + navController.popBackStack() + } + } snackbarHostState.showSnackbar(scope, stringsProvider.snackbar.messageSent) }, ) @@ -256,12 +284,21 @@ fun LetroNavHost( }, ), ) { + val conversationId = it.arguments?.getString(Route.Conversation.KEY_CONVERSATION_ID) ConversationScreen( conversationsStringsProvider = stringsProvider.conversations, onConversationDeleted = { navController.popBackStack() snackbarHostState.showSnackbar(scope, stringsProvider.snackbar.conversationDeleted) }, + onReplyClick = { + navController.navigate( + route = Route.CreateNewMessage.getRouteName( + screenType = CreateNewMessageViewModel.ScreenType.REPLY_TO_EXISTING_CONVERSATION, + conversationId = conversationId, + ), + ) + }, onBackClicked = { navController.popBackStack() }, diff --git a/app/src/main/java/tech/relaycorp/letro/ui/navigation/Route.kt b/app/src/main/java/tech/relaycorp/letro/ui/navigation/Route.kt index 678e3700..78b50157 100644 --- a/app/src/main/java/tech/relaycorp/letro/ui/navigation/Route.kt +++ b/app/src/main/java/tech/relaycorp/letro/ui/navigation/Route.kt @@ -1,6 +1,7 @@ package tech.relaycorp.letro.ui.navigation import tech.relaycorp.letro.contacts.ManageContactViewModel +import tech.relaycorp.letro.messages.compose.CreateNewMessageViewModel /** * Class which contains all possible routes @@ -73,7 +74,18 @@ sealed class Route( name = "create_new_message_route", showTopBar = false, isStatusBarPrimaryColor = false, - ) + ) { + const val KEY_SCREEN_TYPE = "screen_type" + const val KEY_CONVERSATION_ID = "conversation_id" + + fun getRouteName( + @CreateNewMessageViewModel.ScreenType screenType: Int, + conversationId: String? = null, + ) = + "${CreateNewMessage.name}?" + + "$KEY_SCREEN_TYPE=$screenType" + + if (conversationId != null) "&$KEY_CONVERSATION_ID=$conversationId" else "" + } object Conversation : Route( name = "conversation_route",