feat: Update message deletion logic in ChatDetailScreen to remove messages by dialog key

This commit is contained in:
k1ngsterr1
2026-01-13 03:11:17 +05:00
parent 901fb52e63
commit 0e88c52ffc
2 changed files with 13 additions and 7 deletions

View File

@@ -1127,8 +1127,12 @@ fun ChatDetailScreen(
showDeleteConfirm = false showDeleteConfirm = false
scope.launch { scope.launch {
try { try {
// Удаляем все сообщения из диалога // Удаляем все сообщения из диалога по dialog_key
// DELETE FROM messages WHERE ((from_public_key = ? AND to_public_key = ?) OR (from_public_key = ? AND to_public_key = ?)) AND account = ? database.messageDao().deleteDialog(
account = currentUserPublicKey,
dialogKey = user.publicKey
)
// Также пробуем удалить по from/to ключам (на всякий случай)
database.messageDao().deleteMessagesBetweenUsers( database.messageDao().deleteMessagesBetweenUsers(
account = currentUserPublicKey, account = currentUserPublicKey,
user1 = user.publicKey, user1 = user.publicKey,
@@ -1143,9 +1147,10 @@ fun ChatDetailScreen(
} catch (e: Exception) { } catch (e: Exception) {
android.util.Log.e("ChatDetail", "❌ Error deleting chat", e) android.util.Log.e("ChatDetail", "❌ Error deleting chat", e)
} }
} // Выходим ПОСЛЕ удаления
onBack() onBack()
} }
}
) { ) {
Text("Delete", color = Color(0xFFFF3B30)) Text("Delete", color = Color(0xFFFF3B30))
} }

View File

@@ -273,10 +273,11 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
* Открыть диалог * Открыть диалог
*/ */
fun openDialog(publicKey: String, title: String = "", username: String = "") { fun openDialog(publicKey: String, title: String = "", username: String = "") {
if (opponentKey == publicKey) { // 🔥 ВСЕГДА перезагружаем данные - не кешируем, т.к. диалог мог быть удалён
ProtocolManager.addLog("💬 Dialog already open: ${publicKey.take(16)}...") // if (opponentKey == publicKey) {
return // ProtocolManager.addLog("💬 Dialog already open: ${publicKey.take(16)}...")
} // return
// }
// Отменяем предыдущую загрузку // Отменяем предыдущую загрузку
loadingJob?.cancel() loadingJob?.cancel()