Событие печати, смена адреса, иконки
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user