More renaming for chatRoom vs chatMessage list
This commit is contained in:
@@ -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 = "",
|
||||
|
||||
@@ -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<ChatRoomDetailRoute> { backStackEntry ->
|
||||
val route = backStackEntry.toRoute<ChatRoomDetailRoute>()
|
||||
|
||||
ChatRoomMessagingListScreen(
|
||||
ChatRoomMessagingScreen(
|
||||
activeUserPublicKey = route.activeUserPublicKey,
|
||||
chatRoomId = route.chatRoomId,
|
||||
relayHint = route.relayHint,
|
||||
|
||||
@@ -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<Boolean> = 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
|
||||
@@ -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
|
||||
)
|
||||
@@ -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<LocalChatMessage>
|
||||
): ChatMessageListUIState
|
||||
|
||||
data object Error: ChatMessageListUIState
|
||||
data object Loading: ChatMessageListUIState
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package at.torch.compose.ui.view.state
|
||||
|
||||
sealed interface ChatRoomMessageListUIState {
|
||||
data class Loaded(
|
||||
val chatMessageList: List<at.torch.compose.database.model.intermdiate.LocalChatMessage>
|
||||
): ChatRoomMessageListUIState
|
||||
|
||||
data object Error: ChatRoomMessageListUIState
|
||||
data object Loading: ChatRoomMessageListUIState
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user