Исправление работы доставки, прочтения сообщений
This commit is contained in:
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user