From 1d59cf00a8fd34dd3d933342d28ef69b46516199 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Sun, 12 Jul 2026 17:29:31 +0200 Subject: [PATCH] More renaming for chatRoom vs chatMessage list --- .../composable/ChatRoomMessagingListScreen.kt | 46 +++++++++---------- .../ui/composable/navigation/TorchNavHost.kt | 4 +- ...ewModel.kt => ChatMessageListViewModel.kt} | 24 +++++----- ...Model.kt => ChatRoomMessagingViewModel.kt} | 26 +++++------ .../ui/view/state/ChatMessageListUIState.kt | 13 ++++++ .../view/state/ChatRoomMessageListUIState.kt | 11 ----- .../state/ChatRoomMessagingListUIState.kt | 16 ------- .../ui/view/state/ChatRoomMessagingUIState.kt | 16 +++++++ 8 files changed, 79 insertions(+), 77 deletions(-) rename composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/{ChatRoomDetailMessageListViewModel.kt => ChatMessageListViewModel.kt} (96%) rename composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/{ChatRoomMessagingListViewModel.kt => ChatRoomMessagingViewModel.kt} (83%) create mode 100755 composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatMessageListUIState.kt delete mode 100755 composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatRoomMessageListUIState.kt delete mode 100755 composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatRoomMessagingListUIState.kt create mode 100755 composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatRoomMessagingUIState.kt diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/composable/ChatRoomMessagingListScreen.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/composable/ChatRoomMessagingListScreen.kt index 88a1e97c..3cb63a8b 100644 --- a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/composable/ChatRoomMessagingListScreen.kt +++ b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/composable/ChatRoomMessagingListScreen.kt @@ -45,35 +45,35 @@ import at.torch.compose.ui.composable.navigation.routes.Route import at.torch.compose.ui.composable.navigation.routes.SearchMemberToAddToChatRoomRoute import at.torch.compose.ui.composable.widgets.LoadingDataIndicator import at.torch.compose.ui.theme.TorchTheme -import at.torch.compose.ui.view.model.ChatRoomMessagingListViewModel -import at.torch.compose.ui.view.state.ChatRoomMessagingListUIState +import at.torch.compose.ui.view.model.ChatRoomMessagingViewModel +import at.torch.compose.ui.view.state.ChatRoomMessagingUIState import com.vitorpamplona.quartz.nip01Core.core.HexKey @OptIn(ExperimentalMaterial3ExpressiveApi::class, ExperimentalMaterial3Api::class) @Composable -fun ChatRoomMessagingListScreen( +fun ChatRoomMessagingScreen( activeUserPublicKey: HexKey, chatRoomId: String, relayHint: String?, - initialChatRoomMessagingListUIState: ChatRoomMessagingListUIState = ChatRoomMessagingListUIState.Loading, + initialChatRoomMessagingUIState: ChatRoomMessagingUIState = ChatRoomMessagingUIState.Loading, nostrRepository: NostrRepository, chatRepository: ChatRepository, onNavigateToRouteAndPopUpInclusive: (Route) -> Unit, onNavigateToRoute: (Route) -> Unit, ) { - val chatRoomMessagingListViewModel: ChatRoomMessagingListViewModel = viewModel( - factory = ChatRoomMessagingListViewModel.factory( + val chatRoomMessagingViewModel: ChatRoomMessagingViewModel = viewModel( + factory = ChatRoomMessagingViewModel.factory( chatRoomId = chatRoomId, relayHint = relayHint, - initialChatRoomMessagingListUIState = initialChatRoomMessagingListUIState, + initialChatRoomMessagingUIState = initialChatRoomMessagingUIState, nostrRepository = nostrRepository, chatRepository = chatRepository, activeUserPublicKey = activeUserPublicKey ) ) - when (val chatRoomDetailUIState = chatRoomMessagingListViewModel.chatRoomMessagingListUIState) { - is ChatRoomMessagingListUIState.Error -> { + when (val chatRoomDetailUIState = chatRoomMessagingViewModel.chatRoomMessagingUIState) { + is ChatRoomMessagingUIState.Error -> { Column( modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally @@ -86,11 +86,11 @@ fun ChatRoomMessagingListScreen( ) } } - is ChatRoomMessagingListUIState.Loaded -> { + is ChatRoomMessagingUIState.Loaded -> { val textFieldState = rememberTextFieldState() - val chatRoomDetailMessageListViewModel: at.torch.compose.ui.view.model.ChatRoomDetailMessageListViewModel = viewModel( - factory = at.torch.compose.ui.view.model.ChatRoomDetailMessageListViewModel.factory( + val chatMessageListViewModel: at.torch.compose.ui.view.model.ChatMessageListViewModel = viewModel( + factory = at.torch.compose.ui.view.model.ChatMessageListViewModel.factory( localChatRoom = chatRoomDetailUIState.localChatRoom, nostrRepository = nostrRepository, chatRepository = chatRepository @@ -132,12 +132,12 @@ fun ChatRoomMessagingListScreen( modifier = Modifier.weight(1f).fillMaxWidth() ) { key(true) { - chatRoomDetailMessageListViewModel.RenderMessages() + chatMessageListViewModel.RenderMessages() } } key(true) { - chatRoomDetailMessageListViewModel.initiate() + chatMessageListViewModel.initiate() } // TODO: Check that we have direct message relays for this user... @@ -179,7 +179,7 @@ fun ChatRoomMessagingListScreen( } else { IconButton( onClick = { - chatRoomDetailMessageListViewModel.sendMessage( + chatMessageListViewModel.sendMessage( textFieldState = textFieldState ) } @@ -246,7 +246,7 @@ fun ChatRoomMessagingListScreen( } } } - ChatRoomMessagingListUIState.Loading -> { + ChatRoomMessagingUIState.Loading -> { Column( modifier = Modifier.fillMaxWidth().padding( 20.dp @@ -279,7 +279,7 @@ fun ChatRoomMessagingListScreen( ) } } - ChatRoomMessagingListUIState.InitiatingNewChat -> { + ChatRoomMessagingUIState.InitiatingNewChat -> { Column( modifier = Modifier.fillMaxWidth().padding( 20.dp @@ -306,7 +306,7 @@ fun ChatRoomMessagingListScreen( ) LaunchedEffect(true) { - chatRoomMessagingListViewModel.initiateNewChat( + chatRoomMessagingViewModel.initiateNewChat( onNavigateToRouteAndPopUpInclusive ) } @@ -315,24 +315,24 @@ fun ChatRoomMessagingListScreen( } LaunchedEffect(true) { - if (initialChatRoomMessagingListUIState == ChatRoomMessagingListUIState.Loading) { - chatRoomMessagingListViewModel.initiateChatRoomDetail() + if (initialChatRoomMessagingUIState == ChatRoomMessagingUIState.Loading) { + chatRoomMessagingViewModel.initiateChatRoomDetail() } } } @Preview @Composable -private fun ChatRoomMessagingListScreenPreview() { +private fun ChatRoomMessagingScreenPreview() { TorchTheme { Surface( modifier = Modifier.fillMaxSize() ) { - ChatRoomMessagingListScreen( + ChatRoomMessagingScreen( activeUserPublicKey = "", chatRoomId = "publicKey", relayHint = null, - initialChatRoomMessagingListUIState = ChatRoomMessagingListUIState.Loaded( + initialChatRoomMessagingUIState = ChatRoomMessagingUIState.Loaded( localChatRoom = LocalChatRoom( chatRoom = ChatRoom( id = "", diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/composable/navigation/TorchNavHost.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/composable/navigation/TorchNavHost.kt index f55ac0bb..efc91aca 100644 --- a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/composable/navigation/TorchNavHost.kt +++ b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/composable/navigation/TorchNavHost.kt @@ -21,7 +21,7 @@ import at.torch.compose.managers.AuxDatabaseManager import at.torch.compose.ui.composable.ActiveProfileScreen import at.torch.compose.ui.composable.AddMemberToChatRoomConfirmationScreen import at.torch.compose.ui.composable.ChatRoomCreationScreen -import at.torch.compose.ui.composable.ChatRoomMessagingListScreen +import at.torch.compose.ui.composable.ChatRoomMessagingScreen import at.torch.compose.ui.composable.CreateProfileScreen import at.torch.compose.ui.composable.HomeScreen import at.torch.compose.ui.composable.ImplementationPendingScreen @@ -557,7 +557,7 @@ fun TorchNavHost( composable { backStackEntry -> val route = backStackEntry.toRoute() - ChatRoomMessagingListScreen( + ChatRoomMessagingScreen( activeUserPublicKey = route.activeUserPublicKey, chatRoomId = route.chatRoomId, relayHint = route.relayHint, diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/ChatRoomDetailMessageListViewModel.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/ChatMessageListViewModel.kt similarity index 96% rename from composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/ChatRoomDetailMessageListViewModel.kt rename to composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/ChatMessageListViewModel.kt index fd96cb91..83d77b02 100755 --- a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/ChatRoomDetailMessageListViewModel.kt +++ b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/ChatMessageListViewModel.kt @@ -50,7 +50,7 @@ import at.torch.compose.nostr.Relays import at.torch.compose.repository.ChatRepository import at.torch.compose.repository.NostrRepository import at.torch.compose.ui.composable.widgets.profile.ProfileColor -import at.torch.compose.ui.view.state.ChatRoomMessageListUIState +import at.torch.compose.ui.view.state.ChatMessageListUIState import co.touchlab.kermit.Logger import com.vitorpamplona.quartz.marmot.mip03GroupMessages.GroupEvent import com.vitorpamplona.quartz.nip17Dm.settings.ChatMessageRelayListEvent @@ -60,14 +60,14 @@ import kotlinx.coroutines.IO import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.launch -class ChatRoomDetailMessageListViewModel( - initialChatRoomMessageListUIState: ChatRoomMessageListUIState, +class ChatMessageListViewModel( + initialChatMessageListUIState: ChatMessageListUIState, val localChatRoom: LocalChatRoom, val nostrRepository: NostrRepository, val chatRepository: ChatRepository ): ViewModel() { val logger = Logger.withTag(TAG) - var chatRoomMessageListUIState: ChatRoomMessageListUIState by mutableStateOf(initialChatRoomMessageListUIState) + var chatMessageListUIState: ChatMessageListUIState by mutableStateOf(initialChatMessageListUIState) private set val isReceiverChatMessageRelayListMissing: MutableState = mutableStateOf(false) @@ -85,7 +85,7 @@ class ChatRoomDetailMessageListViewModel( localChatRoom.chatRoom.id ).distinctUntilChanged().collect { chatMessages -> logger.d("getChatMessageListByChatRoomId: $chatMessages") - chatRoomMessageListUIState = ChatRoomMessageListUIState.Loaded( + chatMessageListUIState = ChatMessageListUIState.Loaded( chatMessageList = chatMessages ) } @@ -203,8 +203,8 @@ class ChatRoomDetailMessageListViewModel( modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally ) { - when (val chatRoomDetailMessageListUIState = this@ChatRoomDetailMessageListViewModel.chatRoomMessageListUIState) { - ChatRoomMessageListUIState.Error -> { + when (val chatRoomDetailMessageListUIState = this@ChatMessageListViewModel.chatMessageListUIState) { + ChatMessageListUIState.Error -> { Column( modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally @@ -217,7 +217,7 @@ class ChatRoomDetailMessageListViewModel( ) } } - is ChatRoomMessageListUIState.Loaded -> { + is ChatMessageListUIState.Loaded -> { Spacer( modifier = Modifier.weight(1f) ) @@ -385,7 +385,7 @@ class ChatRoomDetailMessageListViewModel( } } } - ChatRoomMessageListUIState.Loading -> { + ChatMessageListUIState.Loading -> { Column( modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally @@ -427,14 +427,14 @@ class ChatRoomDetailMessageListViewModel( const val TAG = "ChatRoomDetailMessageListViewModel" fun factory( - initialChatRoomMessageListUIState: ChatRoomMessageListUIState = ChatRoomMessageListUIState.Loading, + initialChatMessageListUIState: ChatMessageListUIState = ChatMessageListUIState.Loading, localChatRoom: LocalChatRoom, nostrRepository: NostrRepository, chatRepository: ChatRepository ): ViewModelProvider.Factory = viewModelFactory { initializer { - ChatRoomDetailMessageListViewModel( - initialChatRoomMessageListUIState = initialChatRoomMessageListUIState, + ChatMessageListViewModel( + initialChatMessageListUIState = initialChatMessageListUIState, localChatRoom = localChatRoom, nostrRepository = nostrRepository, chatRepository = chatRepository diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/ChatRoomMessagingListViewModel.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/ChatRoomMessagingViewModel.kt similarity index 83% rename from composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/ChatRoomMessagingListViewModel.kt rename to composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/ChatRoomMessagingViewModel.kt index c2d5ff15..da85b2c0 100644 --- a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/ChatRoomMessagingListViewModel.kt +++ b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/model/ChatRoomMessagingViewModel.kt @@ -13,23 +13,23 @@ import at.torch.compose.repository.ChatRepository import at.torch.compose.repository.NostrRepository import at.torch.compose.ui.composable.navigation.routes.ChatRoomDetailRoute import at.torch.compose.ui.composable.navigation.routes.Route -import at.torch.compose.ui.view.state.ChatRoomMessagingListUIState +import at.torch.compose.ui.view.state.ChatRoomMessagingUIState import co.touchlab.kermit.Logger import com.vitorpamplona.quartz.nip01Core.core.HexKey import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.IO import kotlinx.coroutines.launch -class ChatRoomMessagingListViewModel( +class ChatRoomMessagingViewModel( val chatRoomId: String, val activeUserPublicKey: HexKey, val relayHint: String?, - initialChatRoomMessagingListUIState: ChatRoomMessagingListUIState, + initialChatRoomMessagingUIState: ChatRoomMessagingUIState, val nostrRepository: NostrRepository, val chatRepository: ChatRepository ): ViewModel() { - var chatRoomMessagingListUIState: ChatRoomMessagingListUIState by mutableStateOf(initialChatRoomMessagingListUIState) + var chatRoomMessagingUIState: ChatRoomMessagingUIState by mutableStateOf(initialChatRoomMessagingUIState) private set @@ -44,11 +44,11 @@ class ChatRoomMessagingListViewModel( viewModelScope.launch(Dispatchers.IO) { val localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId) - chatRoomMessagingListUIState = if (localChatRoom == null) { + chatRoomMessagingUIState = if (localChatRoom == null) { // Initiate new chat... and navigate to new chat... - ChatRoomMessagingListUIState.InitiatingNewChat + ChatRoomMessagingUIState.InitiatingNewChat } else { - ChatRoomMessagingListUIState.Loaded( + ChatRoomMessagingUIState.Loaded( localChatRoom = localChatRoom ) } @@ -110,7 +110,7 @@ class ChatRoomMessagingListViewModel( val keyPackageEvent = chatRepository.getMarmotKeyPackageForPublicKey(chatRoomId) if (keyPackageEvent == null) { - chatRoomMessagingListUIState = ChatRoomMessagingListUIState.Error("Missing Key Package") // TODO: Introduce missing key package UI State... + chatRoomMessagingUIState = ChatRoomMessagingUIState.Error("Missing Key Package") // TODO: Introduce missing key package UI State... } else { // Create new chat and invite local try { @@ -128,13 +128,13 @@ class ChatRoomMessagingListViewModel( ) ) } catch (e: Throwable) { - chatRoomMessagingListUIState = ChatRoomMessagingListUIState.Error("Failed to create chat") + chatRoomMessagingUIState = ChatRoomMessagingUIState.Error("Failed to create chat") } } } else { - chatRoomMessagingListUIState = ChatRoomMessagingListUIState.Error("Couldn't find profile...") + chatRoomMessagingUIState = ChatRoomMessagingUIState.Error("Couldn't find profile...") } } } @@ -147,16 +147,16 @@ class ChatRoomMessagingListViewModel( activeUserPublicKey: HexKey, chatRoomId: String, relayHint: String?, - initialChatRoomMessagingListUIState: ChatRoomMessagingListUIState = ChatRoomMessagingListUIState.Loading, + initialChatRoomMessagingUIState: ChatRoomMessagingUIState = ChatRoomMessagingUIState.Loading, nostrRepository: NostrRepository, chatRepository: ChatRepository ): ViewModelProvider.Factory = viewModelFactory { initializer { - ChatRoomMessagingListViewModel( + ChatRoomMessagingViewModel( activeUserPublicKey = activeUserPublicKey, chatRoomId = chatRoomId, relayHint = relayHint, - initialChatRoomMessagingListUIState = initialChatRoomMessagingListUIState, + initialChatRoomMessagingUIState = initialChatRoomMessagingUIState, nostrRepository = nostrRepository, chatRepository = chatRepository ) diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatMessageListUIState.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatMessageListUIState.kt new file mode 100755 index 00000000..e49862da --- /dev/null +++ b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatMessageListUIState.kt @@ -0,0 +1,13 @@ +package at.torch.compose.ui.view.state + +import at.torch.compose.database.model.intermdiate.LocalChatMessage + +sealed interface ChatMessageListUIState { + data class Loaded( + val chatMessageList: List + ): ChatMessageListUIState + + data object Error: ChatMessageListUIState + data object Loading: ChatMessageListUIState +} + diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatRoomMessageListUIState.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatRoomMessageListUIState.kt deleted file mode 100755 index 63f797a2..00000000 --- a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatRoomMessageListUIState.kt +++ /dev/null @@ -1,11 +0,0 @@ -package at.torch.compose.ui.view.state - -sealed interface ChatRoomMessageListUIState { - data class Loaded( - val chatMessageList: List - ): ChatRoomMessageListUIState - - data object Error: ChatRoomMessageListUIState - data object Loading: ChatRoomMessageListUIState -} - diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatRoomMessagingListUIState.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatRoomMessagingListUIState.kt deleted file mode 100755 index 7590c93a..00000000 --- a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatRoomMessagingListUIState.kt +++ /dev/null @@ -1,16 +0,0 @@ -package at.torch.compose.ui.view.state - -import at.torch.compose.database.model.intermdiate.LocalChatRoom - -sealed interface ChatRoomMessagingListUIState { - data class Loaded( - val localChatRoom: LocalChatRoom - ): ChatRoomMessagingListUIState - - data class Error( - val message: String - ): ChatRoomMessagingListUIState - data object Loading: ChatRoomMessagingListUIState - data object InitiatingNewChat: ChatRoomMessagingListUIState -} - diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatRoomMessagingUIState.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatRoomMessagingUIState.kt new file mode 100755 index 00000000..cbbf066d --- /dev/null +++ b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/view/state/ChatRoomMessagingUIState.kt @@ -0,0 +1,16 @@ +package at.torch.compose.ui.view.state + +import at.torch.compose.database.model.intermdiate.LocalChatRoom + +sealed interface ChatRoomMessagingUIState { + data class Loaded( + val localChatRoom: LocalChatRoom + ): ChatRoomMessagingUIState + + data class Error( + val message: String + ): ChatRoomMessagingUIState + data object Loading: ChatRoomMessagingUIState + data object InitiatingNewChat: ChatRoomMessagingUIState +} +