Исправление работы доставки, прочтения сообщений

This commit is contained in:
Халимов Рустам
2026-04-20 22:17:29 +03:00
parent fc1cf1fd6e
commit 962323814c
13 changed files with 99 additions and 24 deletions
@@ -153,7 +153,8 @@ class ChatRepositoryImpl @Inject constructor(
Log.d(TAG, "Cached ${entities.size} messages")
}
messages.map { msg -> msg.toDomain(currentUserId, baseUrl).copy(isRead = true) }
// Используем корректную логику из маппера (readBy), а не принудительно true
messages.map { msg -> msg.toDomain(currentUserId, baseUrl) }
} catch (e: Exception) {
Log.e(TAG, "Fetch messages failed", e)
emptyList()
@@ -186,7 +187,7 @@ class ChatRepositoryImpl @Inject constructor(
mediaType = type.uppercase(),
mediaJson = "[]",
reactionsJson = "{}",
isRead = true, replyToId = replyToId,
isRead = false, replyToId = replyToId,
syncStatus = SyncStatus.SYNCING,
isDeletedLocally = false, isEditedLocally = false,
editedContent = null, lastUpdated = currentTime
@@ -243,7 +244,7 @@ class ChatRepositoryImpl @Inject constructor(
else -> MediaType.TEXT
},
reactions = emptyMap(),
isRead = true,
isRead = false,
isPinned = false,
isForwarded = false,
forwardedFromName = null,
+20 -2
View File
@@ -97,6 +97,17 @@ fun MessageDto.toDomain(currentUserId: String, baseUrl: String): Message {
}
}
// Исправленная логика isRead:
// Для своих сообщений: проверяем, прочитал ли кто-то другой (получатели)
// Для чужих сообщений: проверяем, прочитал ли текущий пользователь
val isRead = if (senderId == currentUserId) {
// Своё сообщение: прочитано, если кто-то кроме отправителя в readBy
readBy?.any { it.userId != currentUserId } ?: false
} else {
// Чужое сообщение: прочитано, если текущий пользователь в readBy
readBy?.any { it.userId == currentUserId } ?: false
}
return Message(
id = id,
chatId = chatId ?: "",
@@ -118,7 +129,7 @@ fun MessageDto.toDomain(currentUserId: String, baseUrl: String): Message {
},
mediaType = domainMediaType,
reactions = reactions?.associate { it.emoji to it.count } ?: emptyMap(),
isRead = senderId == currentUserId,
isRead = isRead,
isPinned = isPinned ?: false,
isForwarded = forwardedFromId != null,
forwardedFromName = forwardedFrom?.displayName ?: forwardedFrom?.username,
@@ -127,6 +138,13 @@ fun MessageDto.toDomain(currentUserId: String, baseUrl: String): Message {
}
fun MessageDto.toEntity(baseUrl: String, currentUserId: String, gson: com.google.gson.Gson): core.database.data.MessageEntity {
// Исправленная логика isRead для базы данных
val isRead = if (senderId == currentUserId) {
readBy?.any { it.userId != currentUserId } ?: false
} else {
readBy?.any { it.userId == currentUserId } ?: false
}
return core.database.data.MessageEntity(
id = id,
chatId = chatId ?: "",
@@ -139,7 +157,7 @@ fun MessageDto.toEntity(baseUrl: String, currentUserId: String, gson: com.google
mediaType = type ?: "text",
mediaJson = gson.toJson(media),
reactionsJson = gson.toJson(reactions),
isRead = senderId == currentUserId,
isRead = isRead,
replyToId = replyTo?.id
)
}