feat: Enhance logging and state management in Protocol and MessageRepository; improve dialog read status handling in ChatViewModel
This commit is contained in:
@@ -271,6 +271,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
|
||||
lastReadMessageTimestamp = 0L
|
||||
readReceiptSentForCurrentDialog = false
|
||||
isDialogActive = true // 🔥 Диалог активен!
|
||||
android.util.Log.d("ChatViewModel", "✅ Dialog active flag set to TRUE in openDialog")
|
||||
|
||||
// 📨 Применяем Forward сообщения СРАЗУ после сброса
|
||||
if (hasForward) {
|
||||
@@ -306,7 +307,9 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
|
||||
* Как setCurrentDialogPublicKeyView("") в архиве
|
||||
*/
|
||||
fun closeDialog() {
|
||||
android.util.Log.d("ChatViewModel", "🔒 CLOSE DIALOG")
|
||||
isDialogActive = false
|
||||
android.util.Log.d("ChatViewModel", "❌ Dialog active flag set to FALSE")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -398,8 +401,13 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
// 🔥 Фоновые операции БЕЗ блокировки UI
|
||||
launch(Dispatchers.IO) {
|
||||
// Отмечаем как прочитанные в БД
|
||||
messageDao.markDialogAsRead(account, dialogKey)
|
||||
// 👁️ Отмечаем как прочитанные ТОЛЬКО если диалог активен
|
||||
if (isDialogActive) {
|
||||
android.util.Log.d("ChatViewModel", "📖 Marking dialog as read (dialog is active)")
|
||||
messageDao.markDialogAsRead(account, dialogKey)
|
||||
} else {
|
||||
android.util.Log.d("ChatViewModel", "⏸️ NOT marking as read (dialog not active)")
|
||||
}
|
||||
// 🔥 Пересчитываем счетчики из messages
|
||||
dialogDao.updateDialogFromMessages(account, opponent)
|
||||
|
||||
@@ -464,8 +472,13 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
|
||||
hasMoreMessages = entities.size >= PAGE_SIZE
|
||||
currentOffset = entities.size
|
||||
|
||||
// Фоновые операции
|
||||
messageDao.markDialogAsRead(account, dialogKey)
|
||||
// 👁️ Фоновые операции - НЕ помечаем как прочитанные если диалог неактивен!
|
||||
if (isDialogActive) {
|
||||
android.util.Log.d("ChatViewModel", "📖 Marking dialog as read in refresh (dialog is active)")
|
||||
messageDao.markDialogAsRead(account, dialogKey)
|
||||
} else {
|
||||
android.util.Log.d("ChatViewModel", "⏸️ NOT marking as read in refresh (dialog not active)")
|
||||
}
|
||||
// 🔥 Пересчитываем счетчики из messages
|
||||
dialogDao.updateDialogFromMessages(account, opponent)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user