Simple chat & small fixes

This commit is contained in:
2021-09-12 23:35:23 +03:00
parent f098a9ff12
commit 400ff118b5
51 changed files with 1610 additions and 203 deletions
@@ -1,10 +1,13 @@
package com.meloda.fast.api.model
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize
@Entity(tableName = "conversations")
@Parcelize
data class VkConversation(
@PrimaryKey(autoGenerate = false)
val id: Int,
@@ -18,8 +21,9 @@ data class VkConversation(
val outRead: Int,
val isMarkedUnread: Boolean,
val lastMessageId: Int,
val unreadCount: Int?
) {
val unreadCount: Int?,
val membersCount: Int?
) : Parcelable {
@Ignore
var lastMessage: VkMessage? = null
@@ -1,16 +1,19 @@
package com.meloda.fast.api.model
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize
@Entity(tableName = "groups")
@Parcelize
data class VkGroup(
@PrimaryKey(autoGenerate = false)
val id: Int,
val name: String,
val screenName: String,
val photo200: String?
) {
): Parcelable {
override fun toString() = name.trim()
@@ -1,7 +0,0 @@
package com.meloda.fast.api.model
import com.meloda.fast.api.model.attachments.VkAttachment
data class VkGroupCall(
val initiatorId: Int
) : VkAttachment()
@@ -1,41 +1,69 @@
package com.meloda.fast.api.model
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import com.meloda.fast.api.model.attachments.VkAttachment
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
@Entity(tableName = "messages")
@Parcelize
data class VkMessage(
@PrimaryKey(autoGenerate = false)
val id: Int,
val text: String?,
val text: String? = null,
val isOut: Boolean,
val peerId: Int,
val fromId: Int,
val date: Int,
val action: String?,
val actionMemberId: Int?,
val actionText: String?,
val actionConversationMessageId: Int?,
val actionMessage: String?,
val geoType: String?
) {
val randomId: Int,
val action: String? = null,
val actionMemberId: Int? = null,
val actionText: String? = null,
val actionConversationMessageId: Int? = null,
val actionMessage: String? = null,
val geoType: String? = null
) : Parcelable {
@IgnoredOnParcel
@Ignore
var forwards: List<VkMessage>? = null
@IgnoredOnParcel
@Ignore
var attachments: List<VkAttachment>? = null
fun isPeerChat() = peerId > 2_000_000_000
fun isUser() = fromId > 0
fun isGroup() = fromId < 0
fun isRead(conversation: VkConversation) = conversation.outRead < id
fun getPreparedAction(): Action? {
if (action == null) return null
return Action.parse(action)
}
fun changeId(id: Int) = VkMessage(
id = id,
text = text,
isOut = isOut,
peerId = peerId,
fromId = fromId,
date = date,
randomId = randomId,
action = action,
actionMemberId = actionMemberId,
actionText = actionText,
actionConversationMessageId = actionConversationMessageId,
actionMessage = actionMessage,
geoType = geoType
)
enum class Action(val value: String) {
CHAT_CREATE("chat_create"),
CHAT_PHOTO_UPDATE("chat_photo_update"),
@@ -1,9 +1,12 @@
package com.meloda.fast.api.model
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize
@Entity(tableName = "users")
@Parcelize
data class VkUser(
@PrimaryKey(autoGenerate = false)
val id: Int,
@@ -11,7 +14,7 @@ data class VkUser(
val lastName: String,
val online: Boolean,
val photo200: String?
) {
) : Parcelable {
override fun toString() = "$firstName $lastName".trim()
@@ -0,0 +1,5 @@
package com.meloda.fast.api.model.attachments
data class VkGroupCall(
val initiatorId: Int
) : VkAttachment()
@@ -50,7 +50,8 @@ data class BaseVkConversation(
outRead = outRead,
isMarkedUnread = isMarkedUnread,
lastMessageId = lastMessageId,
unreadCount = unreadCount
unreadCount = unreadCount,
membersCount = chatSettings?.membersCount
).apply { this.lastMessage = lastMessage }
@Parcelize
@@ -40,6 +40,7 @@ data class BaseVkMessage(
peerId = peerId,
fromId = fromId,
date = date,
randomId = randomId,
action = action?.type,
actionMemberId = action?.memberId,
actionText = action?.text,