feat: Enhance dialog deletion logic to ensure complete message removal and cache clearing

This commit is contained in:
k1ngsterr1
2026-01-15 18:13:58 +05:00
parent 842bd4eedb
commit 36976dc747
2 changed files with 36 additions and 10 deletions

View File

@@ -571,7 +571,9 @@ fun ChatsListScreen(
Text( Text(
text = "Delete conversation?", text = "Delete conversation?",
fontWeight = FontWeight.SemiBold, fontWeight = FontWeight.SemiBold,
fontSize = 18.sp fontSize = 18.sp,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
) )
}, },
text = { text = {
@@ -579,7 +581,9 @@ fun ChatsListScreen(
Text( Text(
text = "All messages with $displayName will be permanently deleted. This action cannot be undone.", text = "All messages with $displayName will be permanently deleted. This action cannot be undone.",
fontSize = 15.sp, fontSize = 15.sp,
color = if (isDarkTheme) Color(0xFFAAAAAA) else Color(0xFF666666) color = if (isDarkTheme) Color(0xFFAAAAAA) else Color(0xFF666666),
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
) )
}, },
confirmButton = { confirmButton = {
@@ -625,7 +629,9 @@ fun ChatsListScreen(
Text( Text(
text = "Block user?", text = "Block user?",
fontWeight = FontWeight.SemiBold, fontWeight = FontWeight.SemiBold,
fontSize = 18.sp fontSize = 18.sp,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
) )
}, },
text = { text = {
@@ -633,7 +639,9 @@ fun ChatsListScreen(
Text( Text(
text = "$displayName will no longer be able to send you messages. You can unblock them later.", text = "$displayName will no longer be able to send you messages. You can unblock them later.",
fontSize = 15.sp, fontSize = 15.sp,
color = if (isDarkTheme) Color(0xFFAAAAAA) else Color(0xFF666666) color = if (isDarkTheme) Color(0xFFAAAAAA) else Color(0xFF666666),
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
) )
}, },
confirmButton = { confirmButton = {
@@ -679,7 +687,9 @@ fun ChatsListScreen(
Text( Text(
text = "Unblock user?", text = "Unblock user?",
fontWeight = FontWeight.SemiBold, fontWeight = FontWeight.SemiBold,
fontSize = 18.sp fontSize = 18.sp,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
) )
}, },
text = { text = {
@@ -687,7 +697,9 @@ fun ChatsListScreen(
Text( Text(
text = "$displayName will be able to send you messages again.", text = "$displayName will be able to send you messages again.",
fontSize = 15.sp, fontSize = 15.sp,
color = if (isDarkTheme) Color(0xFFAAAAAA) else Color(0xFF666666) color = if (isDarkTheme) Color(0xFFAAAAAA) else Color(0xFF666666),
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
) )
}, },
confirmButton = { confirmButton = {

View File

@@ -176,10 +176,24 @@ class ChatsListViewModel(application: Application) : AndroidViewModel(applicatio
if (currentAccount.isEmpty()) return if (currentAccount.isEmpty()) return
try { try {
// Удаляем все сообщения // Удаляем все сообщения из диалога по dialog_key
database.messageDao().deleteDialog(currentAccount, opponentKey) database.messageDao().deleteDialog(
// Удаляем диалог account = currentAccount,
database.dialogDao().deleteDialog(currentAccount, opponentKey) dialogKey = opponentKey
)
// Также удаляем по from/to ключам (на всякий случай)
database.messageDao().deleteMessagesBetweenUsers(
account = currentAccount,
user1 = opponentKey,
user2 = currentAccount
)
// Очищаем кеш диалога
database.dialogDao().deleteDialog(
account = currentAccount,
opponentKey = opponentKey
)
android.util.Log.d("ChatsListViewModel", "Dialog deleted successfully: $opponentKey")
} catch (e: Exception) { } catch (e: Exception) {
android.util.Log.e("ChatsListViewModel", "Error deleting dialog", e) android.util.Log.e("ChatsListViewModel", "Error deleting dialog", e)
} }