Событие печати, смена адреса, иконки

This commit is contained in:
Халимов Рустам
2026-04-17 16:23:52 +03:00
parent cea3f4d669
commit 8c00d1376d
20 changed files with 95 additions and 26 deletions
@@ -100,9 +100,9 @@ class ChatDetailViewModel @Inject constructor(
// Ensure SignalR is connected and join the chat room
val token = tokenManager.getToken()
if (token != null) {
val baseUrl = serverConfig.getBaseUrl()
signalrClient.connect(baseUrl, token)
val baseUrl = serverConfig.getBaseUrl()
if (token != null && baseUrl.isNotBlank()) {
signalrClient.connect(baseUrl.removeSuffix("/api/"), token)
signalrClient.joinChat(chatId)
}
@@ -230,6 +230,9 @@ class ChatDetailViewModel @Inject constructor(
_state.update { it.copy(isTyping = false) }
}
}
is ChatEvent.UserStoppedTyping -> {
_state.update { it.copy(isTyping = false) }
}
is ChatEvent.MessagesRead -> {
_state.update { currentState ->
val updatedMessages = currentState.messages.map { msg ->
@@ -285,6 +288,22 @@ class ChatDetailViewModel @Inject constructor(
fun onInputTextChanged(text: String) {
_state.update { it.copy(inputText = text) }
val chatId = currentChatId ?: return
// Отправляем индикатор набора текста
val now = System.currentTimeMillis()
if (now - lastTypingSentTime > 1000) {
signalrClient.sendTypingIndicator(chatId)
lastTypingSentTime = now
// Отправляем "остановился печатать" через 3 секунды
typingTimerJob?.cancel()
typingTimerJob = viewModelScope.launch {
delay(3000)
signalrClient.sendUserStoppedTyping(chatId)
}
}
}
fun sendMessage(onFail: (String) -> Unit = {}) {
@@ -298,7 +317,7 @@ class ChatDetailViewModel @Inject constructor(
val tempId = "temp_${System.currentTimeMillis()}"
val userId = getCurrentUserId()
// Determine mediaType based on attachments
val mediaType = when {
pending.isEmpty() -> chats.domain.model.MediaType.TEXT