feat: Implement user blocking check in MessageRepository and ChatViewModel to ignore messages from blocked users
This commit is contained in:
@@ -242,16 +242,6 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
android.util.Log.d("MessageRepository", "📩 handleIncomingMessage START")
|
||||
android.util.Log.d("MessageRepository", " from: ${packet.fromPublicKey.take(20)}...")
|
||||
|
||||
// 🔥 Генерируем messageId если он пустой (как в Архиве - generateRandomKeyFormSeed)
|
||||
val messageId = if (packet.messageId.isBlank()) {
|
||||
generateMessageId(packet.fromPublicKey, packet.toPublicKey, packet.timestamp)
|
||||
} else {
|
||||
packet.messageId
|
||||
}
|
||||
android.util.Log.d("MessageRepository", " messageId: $messageId (original: ${packet.messageId})")
|
||||
android.util.Log.d("MessageRepository", " currentAccount: ${currentAccount?.take(20) ?: "NULL"}...")
|
||||
android.util.Log.d("MessageRepository", " currentPrivateKey: ${if (currentPrivateKey != null) "SET" else "NULL"}")
|
||||
|
||||
val account = currentAccount ?: run {
|
||||
android.util.Log.e("MessageRepository", "❌ ABORT: currentAccount is NULL!")
|
||||
return
|
||||
@@ -261,6 +251,23 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 🔥 Проверяем, не заблокирован ли отправитель
|
||||
val isBlocked = database.blacklistDao().isUserBlocked(packet.fromPublicKey, account)
|
||||
if (isBlocked) {
|
||||
android.util.Log.d("MessageRepository", "🚫 BLOCKED: Ignoring message from blocked user ${packet.fromPublicKey.take(20)}...")
|
||||
return
|
||||
}
|
||||
|
||||
// 🔥 Генерируем messageId если он пустой (как в Архиве - generateRandomKeyFormSeed)
|
||||
val messageId = if (packet.messageId.isBlank()) {
|
||||
generateMessageId(packet.fromPublicKey, packet.toPublicKey, packet.timestamp)
|
||||
} else {
|
||||
packet.messageId
|
||||
}
|
||||
android.util.Log.d("MessageRepository", " messageId: $messageId (original: ${packet.messageId})")
|
||||
android.util.Log.d("MessageRepository", " currentAccount: ${account.take(20)}...")
|
||||
android.util.Log.d("MessageRepository", " currentPrivateKey: SET")
|
||||
|
||||
// Проверяем, не дубликат ли (используем сгенерированный messageId)
|
||||
val isDuplicate = messageDao.messageExists(account, messageId)
|
||||
android.util.Log.d("MessageRepository", " isDuplicate: $isDuplicate")
|
||||
|
||||
@@ -200,6 +200,12 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
|
||||
val privateKey = myPrivateKey ?: return@launch
|
||||
val account = myPublicKey ?: return@launch
|
||||
|
||||
// 🔥 Проверяем блокировку (как в Архиве)
|
||||
val isBlocked = database.blacklistDao().isUserBlocked(packet.fromPublicKey, account)
|
||||
if (isBlocked) {
|
||||
Log.d(TAG, "🚫 BLOCKED: Ignoring message from blocked user ${packet.fromPublicKey.take(20)}...")
|
||||
return@launch
|
||||
}
|
||||
|
||||
// Расшифровываем в фоне - получаем и текст и plainKeyAndNonce
|
||||
val decryptResult = MessageCrypto.decryptIncomingFull(
|
||||
|
||||
Reference in New Issue
Block a user