illegal token checking

fixes
This commit is contained in:
2021-09-17 16:25:26 +03:00
parent a3a282c32c
commit d1ed98691c
57 changed files with 968 additions and 251 deletions
@@ -33,8 +33,8 @@ data class VkConversation(
fun isUser() = type == "user"
fun isGroup() = type == "group"
fun isInUnread() = inRead != lastMessageId
fun isOutUnread() = outRead != lastMessageId
fun isInUnread() = inRead < lastMessageId
fun isOutUnread() = outRead < lastMessageId
fun isUnread() = isInUnread() || isOutUnread()
@@ -12,8 +12,9 @@ data class VkGroup(
val id: Int,
val name: String,
val screenName: String,
val photo200: String?
): Parcelable {
val photo200: String?,
val membersCount: Int?
) : Parcelable {
override fun toString() = name.trim()
@@ -42,14 +42,31 @@ data class VkMessage(
fun isGroup() = fromId < 0
fun isRead(conversation: VkConversation) = conversation.outRead < id
fun isRead(conversation: VkConversation) =
if (isOut) conversation.outRead < id
else conversation.inRead < id
fun getPreparedAction(): Action? {
if (action == null) return null
return Action.parse(action)
}
fun changeId(id: Int) = VkMessage(
fun copyMessage(
id: Int = this.id,
text: String? = this.text,
isOut: Boolean = this.isOut,
peerId: Int = this.peerId,
fromId: Int = this.fromId,
date: Int = this.date,
randomId: Int = this.randomId,
action: String? = this.action,
actionMemberId: Int? = this.actionMemberId,
actionText: String? = this.actionText,
actionConversationMessageId: Int? = this.actionConversationMessageId,
actionMessage: String? = this.actionMessage,
geoType: String? = this.geoType,
important: Boolean = this.important
) = VkMessage(
id = id,
text = text,
isOut = isOut,
@@ -64,7 +81,10 @@ data class VkMessage(
actionMessage = actionMessage,
geoType = geoType,
important = important
)
).also {
it.attachments = attachments
it.forwards = forwards
}
enum class Action(val value: String) {
CHAT_CREATE("chat_create"),
@@ -13,9 +13,13 @@ data class VkUser(
val firstName: String,
val lastName: String,
val online: Boolean,
val photo200: String?
val photo200: String?,
val lastSeen: Int?,
val lastSeenStatus: String?
) : Parcelable {
override fun toString() = "$firstName $lastName".trim()
override fun toString() = fullName
val fullName get() = "$firstName $lastName".trim()
}
@@ -1,8 +1,23 @@
package com.meloda.fast.api.model.attachments
import com.meloda.fast.api.model.base.attachments.BaseVkSticker
import com.meloda.fast.api.model.base.attachments.StickerSize
import kotlinx.parcelize.Parcelize
@Parcelize
data class VkSticker(
val link: String
) : VkAttachment()
val id: Int,
val productId: Int,
val images: List<BaseVkSticker.Image>,
val backgroundImages: List<BaseVkSticker.Image>
) : VkAttachment() {
fun urlForSize(@StickerSize size: Int): String? {
for (image in images) {
if (image.width == size) return image.url
}
return null
}
}
@@ -25,14 +25,17 @@ data class BaseVkGroup(
@SerializedName("photo_100")
val photo100: String?,
@SerializedName("photo_200")
val photo200: String?
val photo200: String?,
@SerializedName("members_count")
val membersCount: Int?
) : Parcelable {
fun asVkGroup() = VkGroup(
id = -id,
name = name,
screenName = screenName,
photo200 = photo200
photo200 = photo200,
membersCount = membersCount
)
}
@@ -0,0 +1,12 @@
package com.meloda.fast.api.model.base
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
@Parcelize
data class BaseVkLongPoll(
val server: String,
val key: String,
val ts: Int,
val pts: Int
) : Parcelable
@@ -52,7 +52,9 @@ data class BaseVkUser(
firstName = firstName,
lastName = lastName,
online = online == 1,
photo200 = photo200
photo200 = photo200,
lastSeen = onlineInfo?.lastSeen,
lastSeenStatus = onlineInfo?.status
)
}
@@ -1,7 +1,9 @@
package com.meloda.fast.api.model.base.attachments
import android.os.Parcelable
import androidx.annotation.IntDef
import com.google.gson.annotations.SerializedName
import com.meloda.fast.api.model.attachments.VkSticker
import kotlinx.parcelize.Parcelize
@Parcelize
@@ -18,6 +20,13 @@ data class BaseVkSticker(
val animations: List<Animation>?
) : Parcelable {
fun asVkSticker() = VkSticker(
id = stickerId,
productId = productId,
images = images,
backgroundImages = imagesWithBackground
)
@Parcelize
data class Image(
val width: Int,
@@ -31,5 +40,7 @@ data class BaseVkSticker(
val url: String
) : Parcelable
}
}
@IntDef(64, 128, 256, 352)
annotation class StickerSize
@@ -1,7 +1,6 @@
package com.meloda.fast.api.model.request
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
@Parcelize
@@ -59,7 +58,6 @@ data class MessagesSendRequest(
@Parcelize
data class MessagesMarkAsImportantRequest(
@SerializedName("message_ids")
val messagesIds: List<Int>,
val important: Boolean
) : Parcelable {
@@ -70,4 +68,17 @@ data class MessagesMarkAsImportantRequest(
"important" to (if (important) 1 else 0).toString()
)
}
@Parcelize
data class MessagesGetLongPollServerRequest(
val needPts: Boolean,
val version: Int
) : Parcelable {
val map
get() = mutableMapOf(
"need_pts" to (if (needPts) 1 else 0).toString(),
"version" to version.toString()
)
}