Исправлены ложные галочки и синхронизация статусов сообщений
Some checks failed
Android Kernel Build / build (push) Failing after 44m56s
Some checks failed
Android Kernel Build / build (push) Failing after 44m56s
This commit is contained in:
@@ -806,6 +806,15 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
packet.chachaKey
|
||||
}
|
||||
|
||||
val isSelfDialog = packet.toPublicKey.trim() == account
|
||||
// Для исходящих сообщений статус доставки меняется ТОЛЬКО по PacketDelivery.
|
||||
val initialDeliveredStatus =
|
||||
if (isOwnMessage && !isSelfDialog) {
|
||||
DeliveryStatus.WAITING.value
|
||||
} else {
|
||||
DeliveryStatus.DELIVERED.value
|
||||
}
|
||||
|
||||
// Создаем entity для кэша и возможной вставки
|
||||
val entity =
|
||||
MessageEntity(
|
||||
@@ -817,7 +826,7 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
chachaKey = storedChachaKey,
|
||||
read = 0,
|
||||
fromMe = if (isOwnMessage) 1 else 0,
|
||||
delivered = DeliveryStatus.DELIVERED.value,
|
||||
delivered = initialDeliveredStatus,
|
||||
messageId = messageId, // 🔥 Используем сгенерированный messageId!
|
||||
plainMessage = encryptedPlainMessage, // 🔒 Зашифрованный текст
|
||||
attachments = attachmentsJson,
|
||||
@@ -946,18 +955,34 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
// Desktop parity (group): from=groupMember, to=groupId -> mark own group messages as read.
|
||||
if (!isOwnReadSync && isGroupDialogKey(toPublicKey)) {
|
||||
val dialogKey = getDialogKey(toPublicKey)
|
||||
messageDao.markAllAsRead(account, toPublicKey)
|
||||
val updatedRows = messageDao.markAllAsRead(account, toPublicKey)
|
||||
|
||||
val readCount = messageCache[dialogKey]?.value?.count { it.isFromMe && !it.isRead } ?: 0
|
||||
val readCount =
|
||||
messageCache[dialogKey]?.value?.count {
|
||||
it.isFromMe &&
|
||||
!it.isRead &&
|
||||
(it.deliveryStatus == DeliveryStatus.DELIVERED ||
|
||||
it.deliveryStatus == DeliveryStatus.READ)
|
||||
} ?: 0
|
||||
messageCache[dialogKey]?.let { flow ->
|
||||
flow.value =
|
||||
flow.value.map { msg ->
|
||||
if (msg.isFromMe && !msg.isRead) msg.copy(isRead = true) else msg
|
||||
if (msg.isFromMe &&
|
||||
!msg.isRead &&
|
||||
(msg.deliveryStatus == DeliveryStatus.DELIVERED ||
|
||||
msg.deliveryStatus == DeliveryStatus.READ)
|
||||
) {
|
||||
msg.copy(isRead = true, deliveryStatus = DeliveryStatus.READ)
|
||||
} else {
|
||||
msg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_deliveryStatusEvents.tryEmit(DeliveryStatusUpdate(dialogKey, "", DeliveryStatus.READ))
|
||||
MessageLogger.logReadStatus(fromPublicKey = toPublicKey, messagesCount = readCount)
|
||||
if (updatedRows > 0) {
|
||||
_deliveryStatusEvents.tryEmit(DeliveryStatusUpdate(dialogKey, "", DeliveryStatus.READ))
|
||||
}
|
||||
MessageLogger.logReadStatus(fromPublicKey = toPublicKey, messagesCount = minOf(readCount, updatedRows))
|
||||
dialogDao.updateDialogFromMessages(account, toPublicKey)
|
||||
return
|
||||
}
|
||||
@@ -981,20 +1006,36 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
}
|
||||
|
||||
// Opponent read our outgoing messages.
|
||||
messageDao.markAllAsRead(account, opponentKey)
|
||||
val updatedRows = messageDao.markAllAsRead(account, opponentKey)
|
||||
|
||||
val readCount = messageCache[dialogKey]?.value?.count { it.isFromMe && !it.isRead } ?: 0
|
||||
val readCount =
|
||||
messageCache[dialogKey]?.value?.count {
|
||||
it.isFromMe &&
|
||||
!it.isRead &&
|
||||
(it.deliveryStatus == DeliveryStatus.DELIVERED ||
|
||||
it.deliveryStatus == DeliveryStatus.READ)
|
||||
} ?: 0
|
||||
messageCache[dialogKey]?.let { flow ->
|
||||
flow.value =
|
||||
flow.value.map { msg ->
|
||||
if (msg.isFromMe && !msg.isRead) msg.copy(isRead = true) else msg
|
||||
if (msg.isFromMe &&
|
||||
!msg.isRead &&
|
||||
(msg.deliveryStatus == DeliveryStatus.DELIVERED ||
|
||||
msg.deliveryStatus == DeliveryStatus.READ)
|
||||
) {
|
||||
msg.copy(isRead = true, deliveryStatus = DeliveryStatus.READ)
|
||||
} else {
|
||||
msg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Notify current dialog UI: all outgoing messages are now read.
|
||||
_deliveryStatusEvents.tryEmit(DeliveryStatusUpdate(dialogKey, "", DeliveryStatus.READ))
|
||||
// Notify current dialog UI only when there are real DB read updates.
|
||||
if (updatedRows > 0) {
|
||||
_deliveryStatusEvents.tryEmit(DeliveryStatusUpdate(dialogKey, "", DeliveryStatus.READ))
|
||||
}
|
||||
|
||||
MessageLogger.logReadStatus(fromPublicKey = opponentKey, messagesCount = readCount)
|
||||
MessageLogger.logReadStatus(fromPublicKey = opponentKey, messagesCount = minOf(readCount, updatedRows))
|
||||
dialogDao.updateDialogFromMessages(account, opponentKey)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user