Ответы, аудио, голосовые
This commit is contained in:
@@ -4,22 +4,23 @@ import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class UserBasicDto(
|
||||
@SerializedName("id") val id: String,
|
||||
@SerializedName("userName") val userName: String,
|
||||
@SerializedName("displayName") val displayName: String,
|
||||
@SerializedName("avatarUrl") val avatarUrl: String?
|
||||
@SerializedName("username") val username: String? = null,
|
||||
@SerializedName("displayName") val displayName: String? = null,
|
||||
@SerializedName("avatarUrl") val avatarUrl: String? = null
|
||||
)
|
||||
|
||||
data class MessageDto(
|
||||
@SerializedName("id") val id: String,
|
||||
@SerializedName("chatId") val chatId: String,
|
||||
@SerializedName("senderId") val senderId: String,
|
||||
@SerializedName("content") val content: String?,
|
||||
@SerializedName("type") val type: String,
|
||||
@SerializedName("sequenceId") val sequenceId: Int,
|
||||
@SerializedName("createdAt") val createdAt: String,
|
||||
@SerializedName("sender") val sender: UserBasicDto,
|
||||
@SerializedName("chatId") val chatId: String? = null,
|
||||
@SerializedName("senderId") val senderId: String? = null,
|
||||
@SerializedName("content") val content: String? = null,
|
||||
@SerializedName("type") val type: String? = null,
|
||||
@SerializedName("sequenceId") val sequenceId: Int? = null,
|
||||
@SerializedName("createdAt") val createdAt: String? = null,
|
||||
@SerializedName("sender") val sender: UserBasicDto? = null,
|
||||
@SerializedName("media") val media: List<MediaItemDto> = emptyList(),
|
||||
@SerializedName("reactions") val reactions: List<ReactionDto>? = emptyList()
|
||||
@SerializedName("reactions") val reactions: List<ReactionDto>? = emptyList(),
|
||||
@SerializedName("replyTo") val replyTo: MessageDto? = null
|
||||
)
|
||||
|
||||
data class ReactionDto(
|
||||
@@ -31,20 +32,23 @@ data class ReactionDto(
|
||||
data class MediaItemDto(
|
||||
@SerializedName("id") val id: String,
|
||||
@SerializedName("type") val type: String,
|
||||
@SerializedName("url") val url: String
|
||||
@SerializedName("url") val url: String,
|
||||
@SerializedName("filename") val filename: String? = null,
|
||||
@SerializedName("size") val size: Long? = null,
|
||||
@SerializedName("duration") val duration: Double? = null
|
||||
)
|
||||
|
||||
data class ChatDto(
|
||||
@SerializedName("id") val id: String,
|
||||
@SerializedName("type") val type: String,
|
||||
@SerializedName("name") val name: String?,
|
||||
@SerializedName("avatar") val avatar: String?,
|
||||
@SerializedName("unreadCount") val unreadCount: Int,
|
||||
@SerializedName("name") val name: String? = null,
|
||||
@SerializedName("avatar") val avatar: String? = null,
|
||||
@SerializedName("unreadCount") val unreadCount: Int = 0,
|
||||
@SerializedName("messages") val messages: List<MessageDto> = emptyList(),
|
||||
@SerializedName("members") val members: List<ChatMemberDto> = emptyList()
|
||||
)
|
||||
|
||||
data class ChatMemberDto(
|
||||
@SerializedName("userId") val userId: String,
|
||||
@SerializedName("user") val user: UserBasicDto?
|
||||
@SerializedName("user") val user: UserBasicDto? = null
|
||||
)
|
||||
|
||||
@@ -57,12 +57,8 @@ class ChatRepositoryImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Mappers
|
||||
fun ChatDto.toDomain(currentUserId: String, baseUrl: String): Chat {
|
||||
// Если это личный чат и имя пустое, ищем имя собеседника в списке участников
|
||||
val chatName = name ?: if (type == "personal") {
|
||||
members.firstOrNull { it.userId != currentUserId }?.user?.displayName ?: "Unknown Chat"
|
||||
} else "Group Chat"
|
||||
@@ -98,17 +94,26 @@ fun MessageDto.toDomain(baseUrl: String): Message {
|
||||
|
||||
return Message(
|
||||
id = id,
|
||||
chatId = chatId,
|
||||
senderId = senderId,
|
||||
senderName = sender.displayName,
|
||||
senderAvatar = sender.avatarUrl?.ensureAbsoluteUrl(baseUrl),
|
||||
chatId = chatId ?: "",
|
||||
senderId = senderId ?: "",
|
||||
senderName = sender?.displayName ?: "Unknown",
|
||||
senderAvatar = sender?.avatarUrl?.ensureAbsoluteUrl(baseUrl),
|
||||
content = content,
|
||||
sequenceId = sequenceId,
|
||||
createdAt = createdAt,
|
||||
media = media.map { it.url.ensureAbsoluteUrl(baseUrl) },
|
||||
mediaUrl = media.firstOrNull()?.url?.ensureAbsoluteUrl(baseUrl),
|
||||
sequenceId = sequenceId ?: 0,
|
||||
createdAt = createdAt ?: "",
|
||||
media = media.map {
|
||||
chats.domain.model.Media(
|
||||
id = it.id,
|
||||
type = it.type,
|
||||
url = it.url.ensureAbsoluteUrl(baseUrl),
|
||||
filename = it.filename,
|
||||
size = it.size,
|
||||
duration = it.duration
|
||||
)
|
||||
},
|
||||
mediaType = domainMediaType,
|
||||
reactions = reactions?.associate { it.emoji to it.count } ?: emptyMap()
|
||||
reactions = reactions?.associate { it.emoji to it.count } ?: emptyMap(),
|
||||
replyTo = replyTo?.toDomain(baseUrl)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -121,4 +126,3 @@ fun String.ensureAbsoluteUrl(baseUrl: String): String {
|
||||
"$base$path"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user