[wip] chat materials; some experiments with local composition and blur
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
package com.meloda.app.fast.model.api.data
|
||||
|
||||
import com.meloda.app.fast.model.api.domain.VkAttachmentHistoryMessage
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class VkAttachmentHistoryMessageData(
|
||||
@Json(name = "message_id") val messageId: Int,
|
||||
@Json(name = "date") val date: Int,
|
||||
@Json(name = "cmid") val conversationMessageId: Int,
|
||||
@Json(name = "from_id") val fromId: Int,
|
||||
@Json(name = "position") val position: Int,
|
||||
@Json(name = "attachment") val attachment: VkAttachmentItemData
|
||||
) {
|
||||
|
||||
fun toDomain(): VkAttachmentHistoryMessage = VkAttachmentHistoryMessage(
|
||||
messageId = messageId,
|
||||
conversationMessageId = conversationMessageId,
|
||||
date = date,
|
||||
fromId = fromId,
|
||||
position = position,
|
||||
attachment = attachment.toDomain()
|
||||
)
|
||||
}
|
||||
+29
-4
@@ -1,5 +1,7 @@
|
||||
package com.meloda.app.fast.model.api.data
|
||||
|
||||
import com.meloda.app.fast.model.api.domain.VkAttachment
|
||||
import com.meloda.app.fast.model.api.domain.VkUnknownAttachment
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@@ -12,7 +14,7 @@ data class VkAttachmentItemData(
|
||||
@Json(name = "doc") val file: VkFileData?,
|
||||
@Json(name = "link") val link: VkLinkData?,
|
||||
@Json(name = "mini_app") val miniApp: VkMiniAppData?,
|
||||
@Json(name = "audio_message") val voiceMessage: VkAudioMessageData?,
|
||||
@Json(name = "audio_message") val audioMessage: VkAudioMessageData?,
|
||||
@Json(name = "sticker") val sticker: VkStickerData?,
|
||||
@Json(name = "gift") val gift: VkGiftData?,
|
||||
@Json(name = "wall") val wall: VkWallData?,
|
||||
@@ -20,7 +22,7 @@ data class VkAttachmentItemData(
|
||||
@Json(name = "poll") val poll: VkPollData?,
|
||||
@Json(name = "wall_reply") val wallReply: VkWallReplyData?,
|
||||
@Json(name = "call") val call: VkCallData?,
|
||||
@Json(name = "group_call_in_progress") val groupCall: VkGroupCallData?,
|
||||
@Json(name = "group_call_in_progress") val groupCallInProgress: VkGroupCallData?,
|
||||
@Json(name = "curator") val curator: VkCuratorData?,
|
||||
@Json(name = "event") val event: VkEventData?,
|
||||
@Json(name = "story") val story: VkStoryData?,
|
||||
@@ -30,6 +32,29 @@ data class VkAttachmentItemData(
|
||||
@Json(name = "audio_playlist") val audioPlaylist: VkAudioPlaylistData?,
|
||||
@Json(name = "podcast") val podcast: VkPodcastData?
|
||||
) {
|
||||
|
||||
fun getPreparedType(): AttachmentType = AttachmentType.parse(type)
|
||||
fun toDomain(): VkAttachment = when (AttachmentType.parse(type)) {
|
||||
AttachmentType.UNKNOWN -> VkUnknownAttachment
|
||||
AttachmentType.PHOTO -> photo?.toDomain()
|
||||
AttachmentType.VIDEO -> video?.toDomain()
|
||||
AttachmentType.AUDIO -> audio?.toDomain()
|
||||
AttachmentType.FILE -> file?.toDomain()
|
||||
AttachmentType.LINK -> link?.toDomain()
|
||||
AttachmentType.MINI_APP -> miniApp?.toDomain()
|
||||
AttachmentType.AUDIO_MESSAGE -> audioMessage?.toDomain()
|
||||
AttachmentType.STICKER -> sticker?.toDomain()
|
||||
AttachmentType.GIFT -> gift?.toDomain()
|
||||
AttachmentType.WALL -> wall?.toDomain()
|
||||
AttachmentType.GRAFFITI -> graffiti?.toDomain()
|
||||
AttachmentType.POLL -> poll?.toDomain()
|
||||
AttachmentType.WALL_REPLY -> wallReply?.toDomain()
|
||||
AttachmentType.CALL -> call?.toDomain()
|
||||
AttachmentType.GROUP_CALL_IN_PROGRESS -> groupCallInProgress?.toDomain()
|
||||
AttachmentType.CURATOR -> curator?.toDomain()
|
||||
AttachmentType.EVENT -> event?.toDomain()
|
||||
AttachmentType.STORY -> story?.toDomain()
|
||||
AttachmentType.WIDGET -> widget?.toDomain()
|
||||
AttachmentType.ARTIST -> artist?.toDomain()
|
||||
AttachmentType.AUDIO_PLAYLIST -> audioPlaylist?.toDomain()
|
||||
AttachmentType.PODCAST -> podcast?.toDomain()
|
||||
} ?: VkUnknownAttachment
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.meloda.app.fast.model.api.data
|
||||
|
||||
import com.meloda.app.fast.model.api.domain.VkAttachment
|
||||
import com.meloda.app.fast.model.api.domain.VkMessage
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
@@ -60,6 +59,7 @@ data class VkMessageData(
|
||||
|
||||
fun VkMessageData.asDomain(): VkMessage = VkMessage(
|
||||
id = id ?: -1,
|
||||
conversationMessageId = conversationMessageId,
|
||||
text = text.ifBlank { null },
|
||||
isOut = out == 1,
|
||||
peerId = peerId ?: -1,
|
||||
@@ -75,134 +75,10 @@ fun VkMessageData.asDomain(): VkMessage = VkMessage(
|
||||
important = important,
|
||||
updateTime = updateTime,
|
||||
forwards = fwdMessages.orEmpty().map(VkMessageData::asDomain),
|
||||
attachments = parseAttachments(),
|
||||
attachments = attachments.map(VkAttachmentItemData::toDomain),
|
||||
replyMessage = replyMessage?.asDomain(),
|
||||
user = null,
|
||||
group = null,
|
||||
actionUser = null,
|
||||
actionGroup = null,
|
||||
)
|
||||
|
||||
private fun VkMessageData.parseAttachments(): List<VkAttachment> {
|
||||
if (attachments.isEmpty()) return emptyList()
|
||||
|
||||
val attachments = mutableListOf<VkAttachment>()
|
||||
|
||||
for (baseAttachment in this.attachments) {
|
||||
when (baseAttachment.getPreparedType()) {
|
||||
AttachmentType.UNKNOWN -> continue
|
||||
AttachmentType.PHOTO -> {
|
||||
val photo = baseAttachment.photo ?: continue
|
||||
attachments += photo.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.VIDEO -> {
|
||||
val video = baseAttachment.video ?: continue
|
||||
attachments += video.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.AUDIO -> {
|
||||
val audio = baseAttachment.audio ?: continue
|
||||
attachments += audio.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.FILE -> {
|
||||
val file = baseAttachment.file ?: continue
|
||||
attachments += file.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.LINK -> {
|
||||
val link = baseAttachment.link ?: continue
|
||||
attachments += link.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.MINI_APP -> {
|
||||
val miniApp = baseAttachment.miniApp ?: continue
|
||||
attachments += miniApp.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.AUDIO_MESSAGE -> {
|
||||
val voiceMessage = baseAttachment.voiceMessage ?: continue
|
||||
attachments += voiceMessage.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.STICKER -> {
|
||||
val sticker = baseAttachment.sticker ?: continue
|
||||
attachments += sticker.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.GIFT -> {
|
||||
val gift = baseAttachment.gift ?: continue
|
||||
attachments += gift.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.WALL -> {
|
||||
val wall = baseAttachment.wall ?: continue
|
||||
attachments += wall.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.GRAFFITI -> {
|
||||
val graffiti = baseAttachment.graffiti ?: continue
|
||||
attachments += graffiti.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.POLL -> {
|
||||
val poll = baseAttachment.poll ?: continue
|
||||
attachments += poll.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.WALL_REPLY -> {
|
||||
val wallReply = baseAttachment.wallReply ?: continue
|
||||
attachments += wallReply.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.CALL -> {
|
||||
val call = baseAttachment.call ?: continue
|
||||
attachments += call.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.GROUP_CALL_IN_PROGRESS -> {
|
||||
val groupCall = baseAttachment.groupCall ?: continue
|
||||
attachments += groupCall.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.CURATOR -> {
|
||||
val curator = baseAttachment.curator ?: continue
|
||||
attachments += curator.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.EVENT -> {
|
||||
val event = baseAttachment.event ?: continue
|
||||
attachments += event.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.STORY -> {
|
||||
val story = baseAttachment.story ?: continue
|
||||
attachments += story.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.WIDGET -> {
|
||||
val widget = baseAttachment.widget ?: continue
|
||||
attachments += widget.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.ARTIST -> {
|
||||
val artist = baseAttachment.artist ?: continue
|
||||
attachments += artist.toDomain()
|
||||
val audios = baseAttachment.audios ?: continue
|
||||
audios.map(VkAudioData::toDomain).let(attachments::addAll)
|
||||
}
|
||||
|
||||
AttachmentType.AUDIO_PLAYLIST -> {
|
||||
val audioPlaylist = baseAttachment.audioPlaylist ?: continue
|
||||
attachments += audioPlaylist.toDomain()
|
||||
}
|
||||
|
||||
AttachmentType.PODCAST -> {
|
||||
val podcast = baseAttachment.podcast ?: continue
|
||||
attachments += podcast.toDomain()
|
||||
}
|
||||
}
|
||||
}
|
||||
return attachments
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ data class VkPinnedMessageData(
|
||||
|
||||
fun mapToDomain(): VkMessage = VkMessage(
|
||||
id = id ?: -1,
|
||||
conversationMessageId = conversationMessageId,
|
||||
text = text.ifBlank { null },
|
||||
isOut = out == true,
|
||||
peerId = peerId ?: -1,
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.meloda.app.fast.model.api.domain
|
||||
|
||||
data class VkAttachmentHistoryMessage(
|
||||
val messageId: Int,
|
||||
val conversationMessageId: Int,
|
||||
val date: Int,
|
||||
val fromId: Int,
|
||||
val position: Int,
|
||||
val attachment: VkAttachment
|
||||
)
|
||||
@@ -4,6 +4,7 @@ import com.meloda.app.fast.model.database.VkMessageEntity
|
||||
|
||||
data class VkMessage(
|
||||
val id: Int,
|
||||
val conversationMessageId: Int,
|
||||
val text: String?,
|
||||
val isOut: Boolean,
|
||||
val peerId: Int,
|
||||
@@ -78,6 +79,7 @@ data class VkMessage(
|
||||
|
||||
fun VkMessage.asEntity(): VkMessageEntity = VkMessageEntity(
|
||||
id = id,
|
||||
conversationMessageId = conversationMessageId,
|
||||
text = text,
|
||||
isOut = isOut,
|
||||
peerId = peerId,
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.meloda.app.fast.model.api.domain
|
||||
|
||||
import com.meloda.app.fast.model.api.data.AttachmentType
|
||||
|
||||
data object VkUnknownAttachment : VkAttachment {
|
||||
override val type: AttachmentType = AttachmentType.UNKNOWN
|
||||
}
|
||||
@@ -243,3 +243,27 @@ data class MessagesRemoveChatUserRequest(
|
||||
"member_id" to memberId.toString()
|
||||
)
|
||||
}
|
||||
|
||||
data class MessagesGetHistoryAttachmentsRequest(
|
||||
val peerId: Int,
|
||||
val extended: Boolean?,
|
||||
val count: Int?,
|
||||
val offset: Int?,
|
||||
val preserveOrder: Boolean?,
|
||||
val attachmentTypes: List<String>,
|
||||
val conversationMessageId: Int,
|
||||
val fields: String?
|
||||
) {
|
||||
|
||||
val map = mutableMapOf(
|
||||
"peer_id" to peerId.toString(),
|
||||
"attachment_types" to attachmentTypes.joinToString(","),
|
||||
"cmid" to conversationMessageId.toString()
|
||||
).apply {
|
||||
extended?.let { this["extended"] = it.toString() }
|
||||
count?.let { this["count"] = it.toString() }
|
||||
offset?.let { this["offset"] = it.toString() }
|
||||
preserveOrder?.let { this["preserve_order"] = it.toString() }
|
||||
fields?.let { this["fields"] = it }
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -1,11 +1,13 @@
|
||||
package com.meloda.app.fast.model.api.responses
|
||||
|
||||
import com.meloda.app.fast.model.api.data.VkAttachmentHistoryMessageData
|
||||
import com.meloda.app.fast.model.api.data.VkChatMemberData
|
||||
import com.meloda.app.fast.model.api.data.VkContactData
|
||||
import com.meloda.app.fast.model.api.data.VkConversationData
|
||||
import com.meloda.app.fast.model.api.data.VkGroupData
|
||||
import com.meloda.app.fast.model.api.data.VkMessageData
|
||||
import com.meloda.app.fast.model.api.data.VkUserData
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
@@ -33,3 +35,12 @@ data class MessagesGetConversationMembersResponse(
|
||||
val profiles: List<VkUserData>?,
|
||||
val groups: List<VkGroupData>?
|
||||
)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class MessagesGetHistoryAttachmentsResponse(
|
||||
@Json(name = "items") val items: List<VkAttachmentHistoryMessageData>,
|
||||
@Json(name = "next_from") val nextFrom: String?,
|
||||
@Json(name = "profiles") val profiles: List<VkUserData>?,
|
||||
@Json(name = "groups") val groups: List<VkGroupData>?,
|
||||
@Json(name = "contacts") val contacts: List<VkContactData>?
|
||||
)
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.meloda.app.fast.model.api.domain.VkMessage
|
||||
@Entity(tableName = "messages")
|
||||
data class VkMessageEntity(
|
||||
@PrimaryKey val id: Int,
|
||||
val conversationMessageId: Int,
|
||||
val text: String?,
|
||||
val isOut: Boolean,
|
||||
val peerId: Int,
|
||||
@@ -29,6 +30,7 @@ data class VkMessageEntity(
|
||||
|
||||
fun VkMessageEntity.asExternalModel(): VkMessage = VkMessage(
|
||||
id = id,
|
||||
conversationMessageId = conversationMessageId,
|
||||
text = text,
|
||||
isOut = isOut,
|
||||
peerId = peerId,
|
||||
|
||||
Reference in New Issue
Block a user