Авторизация, нерабочий чат

This commit is contained in:
Халимов Рустам
2026-04-14 01:41:51 +03:00
parent 1fb1be47dd
commit dc051fa9ae
22 changed files with 160 additions and 49 deletions
@@ -7,6 +7,7 @@ import chats.domain.repository.ChatRepository
import chats.data.remote.signalr.ChatHubClient
import chats.data.remote.signalr.ChatEvent
import core.network.ServerConfig
import core.security.TokenManager
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
@@ -24,7 +25,8 @@ data class ChatListState(
class ChatListViewModel @Inject constructor(
private val repository: ChatRepository,
private val signalrClient: ChatHubClient,
private val serverConfig: ServerConfig
private val serverConfig: ServerConfig,
private val tokenManager: TokenManager
) : ViewModel() {
private val _state = MutableStateFlow(ChatListState())
@@ -41,6 +43,8 @@ class ChatListViewModel @Inject constructor(
observeSignalREvents()
}
private fun getCurrentUserId(): String = tokenManager.getUserId() ?: ""
fun loadChats() {
viewModelScope.launch {
_state.update { it.copy(isLoading = true) }
@@ -61,7 +65,8 @@ class ChatListViewModel @Inject constructor(
updateChatsWithNewMessage(event)
}
is ChatEvent.NewChat -> {
_state.update { it.copy(chats = listOf(event.chat.toDomain()) + it.chats) }
val currentUserId = getCurrentUserId()
_state.update { it.copy(chats = listOf(event.chat.toDomain(currentUserId)) + it.chats) }
}
else -> Unit
}
@@ -69,6 +74,7 @@ class ChatListViewModel @Inject constructor(
.launchIn(viewModelScope)
}
private fun updateChatsWithNewMessage(event: ChatEvent.NewMessage) {
_state.update { currentState ->
val updatedChats = currentState.chats.map { chat ->