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
scope.launch {
try {
// Удаляем все сообщения из диалога
// DELETE FROM messages WHERE ((from_public_key = ? AND to_public_key = ?) OR (from_public_key = ? AND to_public_key = ?)) AND account = ?
// Удаляем все сообщения из диалога по dialog_key
database.messageDao().deleteDialog(
account = currentUserPublicKey,
dialogKey = user.publicKey
)
// Также пробуем удалить по from/to ключам (на всякий случай)
database.messageDao().deleteMessagesBetweenUsers(
account = currentUserPublicKey,
user1 = user.publicKey,
@@ -1143,9 +1147,10 @@ fun ChatDetailScreen(
} catch (e: Exception) {
android.util.Log.e("ChatDetail", "❌ Error deleting chat", e)
}
}
// Выходим ПОСЛЕ удаления
onBack()
}
}
) {
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 = "") {
if (opponentKey == publicKey) {
ProtocolManager.addLog("💬 Dialog already open: ${publicKey.take(16)}...")
return
}
// 🔥 ВСЕГДА перезагружаем данные - не кешируем, т.к. диалог мог быть удалён
// if (opponentKey == publicKey) {
// ProtocolManager.addLog("💬 Dialog already open: ${publicKey.take(16)}...")
// return
// }
// Отменяем предыдущую загрузку
loadingJob?.cancel()