Rename ChatRoomDetail files to ChatRoomMesssagingList
This commit is contained in:
@@ -302,7 +302,6 @@ abstract class MarmotOutboundDao(
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
// Save chatMessage for the invite...
|
||||
database.chatMessageDao().upsert(
|
||||
ChatMessage(
|
||||
|
||||
@@ -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.ChatRoomDetailViewModel
|
||||
import at.torch.compose.ui.view.state.ChatRoomDetailUIState
|
||||
import at.torch.compose.ui.view.model.ChatRoomMessagingListViewModel
|
||||
import at.torch.compose.ui.view.state.ChatRoomMessagingListUIState
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class, ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ChatRoomDetailScreen(
|
||||
fun ChatRoomMessagingListScreen(
|
||||
activeUserPublicKey: HexKey,
|
||||
chatRoomId: String,
|
||||
relayHint: String?,
|
||||
initialChatRoomDetailUIState: ChatRoomDetailUIState = ChatRoomDetailUIState.Loading,
|
||||
initialChatRoomMessagingListUIState: ChatRoomMessagingListUIState = ChatRoomMessagingListUIState.Loading,
|
||||
nostrRepository: NostrRepository,
|
||||
chatRepository: ChatRepository,
|
||||
onNavigateToRouteAndPopUpInclusive: (Route) -> Unit,
|
||||
onNavigateToRoute: (Route) -> Unit,
|
||||
) {
|
||||
val chatRoomDetailViewModel: ChatRoomDetailViewModel = viewModel(
|
||||
factory = ChatRoomDetailViewModel.factory(
|
||||
val chatRoomMessagingListViewModel: ChatRoomMessagingListViewModel = viewModel(
|
||||
factory = ChatRoomMessagingListViewModel.factory(
|
||||
chatRoomId = chatRoomId,
|
||||
relayHint = relayHint,
|
||||
initialChatRoomDetailUIState = initialChatRoomDetailUIState,
|
||||
initialChatRoomMessagingListUIState = initialChatRoomMessagingListUIState,
|
||||
nostrRepository = nostrRepository,
|
||||
chatRepository = chatRepository,
|
||||
activeUserPublicKey = activeUserPublicKey
|
||||
)
|
||||
)
|
||||
|
||||
when (val chatRoomDetailUIState = chatRoomDetailViewModel.chatRoomDetailUIState) {
|
||||
is ChatRoomDetailUIState.Error -> {
|
||||
when (val chatRoomDetailUIState = chatRoomMessagingListViewModel.chatRoomMessagingListUIState) {
|
||||
is ChatRoomMessagingListUIState.Error -> {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
@@ -86,7 +86,7 @@ fun ChatRoomDetailScreen(
|
||||
)
|
||||
}
|
||||
}
|
||||
is ChatRoomDetailUIState.Loaded -> {
|
||||
is ChatRoomMessagingListUIState.Loaded -> {
|
||||
val textFieldState = rememberTextFieldState()
|
||||
|
||||
val chatRoomDetailMessageListViewModel: at.torch.compose.ui.view.model.ChatRoomDetailMessageListViewModel = viewModel(
|
||||
@@ -246,7 +246,7 @@ fun ChatRoomDetailScreen(
|
||||
}
|
||||
}
|
||||
}
|
||||
ChatRoomDetailUIState.Loading -> {
|
||||
ChatRoomMessagingListUIState.Loading -> {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(
|
||||
20.dp
|
||||
@@ -279,7 +279,7 @@ fun ChatRoomDetailScreen(
|
||||
)
|
||||
}
|
||||
}
|
||||
ChatRoomDetailUIState.InitiatingNewChat -> {
|
||||
ChatRoomMessagingListUIState.InitiatingNewChat -> {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(
|
||||
20.dp
|
||||
@@ -306,7 +306,7 @@ fun ChatRoomDetailScreen(
|
||||
)
|
||||
|
||||
LaunchedEffect(true) {
|
||||
chatRoomDetailViewModel.initiateNewChat(
|
||||
chatRoomMessagingListViewModel.initiateNewChat(
|
||||
onNavigateToRouteAndPopUpInclusive
|
||||
)
|
||||
}
|
||||
@@ -315,24 +315,24 @@ fun ChatRoomDetailScreen(
|
||||
}
|
||||
|
||||
LaunchedEffect(true) {
|
||||
if (initialChatRoomDetailUIState == ChatRoomDetailUIState.Loading) {
|
||||
chatRoomDetailViewModel.initiateChatRoomDetail()
|
||||
if (initialChatRoomMessagingListUIState == ChatRoomMessagingListUIState.Loading) {
|
||||
chatRoomMessagingListViewModel.initiateChatRoomDetail()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun ChatRoomDetailScreenPreview() {
|
||||
private fun ChatRoomMessagingListScreenPreview() {
|
||||
TorchTheme {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
ChatRoomDetailScreen(
|
||||
ChatRoomMessagingListScreen(
|
||||
activeUserPublicKey = "",
|
||||
chatRoomId = "publicKey",
|
||||
relayHint = null,
|
||||
initialChatRoomDetailUIState = ChatRoomDetailUIState.Loaded(
|
||||
initialChatRoomMessagingListUIState = ChatRoomMessagingListUIState.Loaded(
|
||||
localChatRoom = LocalChatRoom(
|
||||
chatRoom = ChatRoom(
|
||||
id = "",
|
||||
@@ -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.ChatRoomDetailScreen
|
||||
import at.torch.compose.ui.composable.ChatRoomMessagingListScreen
|
||||
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<ChatRoomDetailRoute> { backStackEntry ->
|
||||
val route = backStackEntry.toRoute<ChatRoomDetailRoute>()
|
||||
|
||||
ChatRoomDetailScreen(
|
||||
ChatRoomMessagingListScreen(
|
||||
activeUserPublicKey = route.activeUserPublicKey,
|
||||
chatRoomId = route.chatRoomId,
|
||||
relayHint = route.relayHint,
|
||||
|
||||
@@ -13,24 +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.ChatRoomDetailUIState
|
||||
import at.torch.compose.ui.view.state.ChatRoomMessagingListUIState
|
||||
import co.touchlab.kermit.Logger
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.IO
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class ChatRoomDetailViewModel(
|
||||
class ChatRoomMessagingListViewModel(
|
||||
val chatRoomId: String,
|
||||
val activeUserPublicKey: HexKey,
|
||||
val relayHint: String?,
|
||||
initialChatRoomDetailUIState: ChatRoomDetailUIState,
|
||||
initialChatRoomMessagingListUIState: ChatRoomMessagingListUIState,
|
||||
val nostrRepository: NostrRepository,
|
||||
val chatRepository: ChatRepository
|
||||
): ViewModel() {
|
||||
|
||||
var chatRoomDetailUIState: ChatRoomDetailUIState by mutableStateOf(initialChatRoomDetailUIState)
|
||||
var chatRoomMessagingListUIState: ChatRoomMessagingListUIState by mutableStateOf(initialChatRoomMessagingListUIState)
|
||||
private set
|
||||
|
||||
|
||||
@@ -45,11 +44,11 @@ class ChatRoomDetailViewModel(
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId)
|
||||
|
||||
chatRoomDetailUIState = if (localChatRoom == null) {
|
||||
chatRoomMessagingListUIState = if (localChatRoom == null) {
|
||||
// Initiate new chat... and navigate to new chat...
|
||||
ChatRoomDetailUIState.InitiatingNewChat
|
||||
ChatRoomMessagingListUIState.InitiatingNewChat
|
||||
} else {
|
||||
ChatRoomDetailUIState.Loaded(
|
||||
ChatRoomMessagingListUIState.Loaded(
|
||||
localChatRoom = localChatRoom
|
||||
)
|
||||
}
|
||||
@@ -111,7 +110,7 @@ class ChatRoomDetailViewModel(
|
||||
val keyPackageEvent = chatRepository.getMarmotKeyPackageForPublicKey(chatRoomId)
|
||||
|
||||
if (keyPackageEvent == null) {
|
||||
chatRoomDetailUIState = ChatRoomDetailUIState.Error("Missing Key Package") // TODO: Introduce missing key package UI State...
|
||||
chatRoomMessagingListUIState = ChatRoomMessagingListUIState.Error("Missing Key Package") // TODO: Introduce missing key package UI State...
|
||||
} else {
|
||||
// Create new chat and invite local
|
||||
try {
|
||||
@@ -129,13 +128,13 @@ class ChatRoomDetailViewModel(
|
||||
)
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
chatRoomDetailUIState = ChatRoomDetailUIState.Error("Failed to create chat")
|
||||
chatRoomMessagingListUIState = ChatRoomMessagingListUIState.Error("Failed to create chat")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
chatRoomDetailUIState = ChatRoomDetailUIState.Error("Couldn't find profile...")
|
||||
chatRoomMessagingListUIState = ChatRoomMessagingListUIState.Error("Couldn't find profile...")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,16 +147,16 @@ class ChatRoomDetailViewModel(
|
||||
activeUserPublicKey: HexKey,
|
||||
chatRoomId: String,
|
||||
relayHint: String?,
|
||||
initialChatRoomDetailUIState: ChatRoomDetailUIState = ChatRoomDetailUIState.Loading,
|
||||
initialChatRoomMessagingListUIState: ChatRoomMessagingListUIState = ChatRoomMessagingListUIState.Loading,
|
||||
nostrRepository: NostrRepository,
|
||||
chatRepository: ChatRepository
|
||||
): ViewModelProvider.Factory = viewModelFactory {
|
||||
initializer {
|
||||
ChatRoomDetailViewModel(
|
||||
ChatRoomMessagingListViewModel(
|
||||
activeUserPublicKey = activeUserPublicKey,
|
||||
chatRoomId = chatRoomId,
|
||||
relayHint = relayHint,
|
||||
initialChatRoomDetailUIState = initialChatRoomDetailUIState,
|
||||
initialChatRoomMessagingListUIState = initialChatRoomMessagingListUIState,
|
||||
nostrRepository = nostrRepository,
|
||||
chatRepository = chatRepository
|
||||
)
|
||||
@@ -1,16 +0,0 @@
|
||||
package at.torch.compose.ui.view.state
|
||||
|
||||
import at.torch.compose.database.model.intermdiate.LocalChatRoom
|
||||
|
||||
sealed interface ChatRoomDetailUIState {
|
||||
data class Loaded(
|
||||
val localChatRoom: LocalChatRoom
|
||||
): ChatRoomDetailUIState
|
||||
|
||||
data class Error(
|
||||
val message: String
|
||||
): ChatRoomDetailUIState
|
||||
data object Loading: ChatRoomDetailUIState
|
||||
data object InitiatingNewChat: ChatRoomDetailUIState
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user