Skip to content

Commit

Permalink
7
Browse files Browse the repository at this point in the history
Last Int Owner
  • Loading branch information
umerov1999 committed Jan 15, 2023
1 parent 9ca39ff commit 2f99cd9
Show file tree
Hide file tree
Showing 194 changed files with 858 additions and 657 deletions.
178 changes: 87 additions & 91 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/Extra.kt
Original file line number Diff line number Diff line change
@@ -1,119 +1,115 @@
package dev.ragnarok.fenrir

object Extra {
const val PRIVACY = "domain"
const val DOMAIN = "domain"
const val URL = "url"
const val ACTION = "action"
const val COUNTERS = "counters"
const val TOKEN = "token"
const val LOGIN = "login"
const val PASSWORD = "password"
const val TWO_FA = "two_fa"
const val ACCESS_KEY = "access_key"
const val ACCOUNT_ID = "account_id"
const val CAPTCHA_URL = "captcha_url"
const val CAPTCHA_SID = "captcha_sid"
const val PHOTOS = "photos"
const val OWNER = "owner"
const val OWNERS = "owners"
const val OWNER_ID = "owner_id"
const val ITEM_ID = "item_id"
const val ACTION = "action"
const val ALBUM = "album"
const val ALBUM_ID = "album_id"
const val POST_ID = "post_id"
const val FILTER = "filter"
const val ID = "id"
const val ANSWER = "answer"
const val ARTIST = "artist"
const val ATTACHMENTS = "attachments"
const val ACCESS_KEY = "access_key"
const val LIST = "list"
const val VIDEO = "video"
const val ATTRS = "attrs"
const val AUDIOS = "audios"
const val BANNED = "banned"
const val BODY = "body"
const val BUNDLE = "bundle"
const val CAPTCHA_SID = "captcha_sid"
const val CAPTCHA_URL = "captcha_url"
const val CHAIR = "chair"
const val CHAIR_ID = "chair_id"
const val CHAT_ID = "chat_id"
const val CITY = "city"
const val CITY_ID = "city_id"
const val COMMENT = "comment"
const val COMMENTED = "commented"
const val COMMENT_ID = "comment_id"
const val TYPE = "type"
const val RANGE = "range"
const val COUNT = "count"
const val SORT = "sort"
const val POST = "post"
const val MESSAGE_ID = "message_id"
const val PEER_ID = "peer_id"
const val TITLE = "title"
const val HIDE_TITLE = "hide_title"
const val USER_ID = "user_id"
const val AUDIOS = "audios"
const val POSITION = "position"
const val SHUFFLE_MODE = "shuffle_mode"
const val USERS = "users"
const val USER = "user"
const val COUNTERS = "counters"
const val COUNTRY = "country"
const val CRITERIA = "criteria"
const val VIDEOS = "videos"
const val DOCS = "docs"
const val DOC = "doc"
const val DOCS = "docs"
const val DOC_ID = "doc_id"
const val TAB = "tab"
const val ALL = "all"
const val COUNTRY = "country"
const val CITY = "city"
const val UNIVERSITY = "university"
const val DOMAIN = "domain"
const val ERROR = "error"
const val EXT = "ext"
const val FACULTY = "faculty"
const val FACULTY_ID = "faculty_id"
const val CHAIR_ID = "chair_id"
const val UNIVERSITY_ID = "university_id"
const val CITY_ID = "city_id"
const val KEY = "key"
const val FILTER = "filter"
const val FOCUS_TO = "focus_to"
const val GROUP = "group"
const val GROUP_ID = "group_id"
const val PLACE = "place"
const val HIDE_TITLE = "hide_title"
const val ID = "id"
const val IMAGE = "image"
const val CHAT_ID = "chat_id"
const val CHAIR = "chair"
const val INCOMING = "incoming"
const val INDEX = "index"
const val INVERT = "invert"
const val IS_BOARD = "is_board"
const val IS_OUT_OF_MEMORY = "is_out_of_memory"
const val ITEM_ID = "item_id"
const val KEY = "key"
const val LIST = "list"
const val LOGIN = "login"
const val MANAGER = "manager"
const val MARKET = "market"
const val MAX_COUNT = "max_count"
const val MESSAGE = "message"
const val MESSAGES = "messages"
const val MESSAGE_ID = "message_id"
const val METHOD = "method"
const val NEW = "new"
const val OLD = "old"
const val OUTGOING = "outgoing"
const val OWNER = "owner"
const val OWNERS = "owners"
const val OWNER_ID = "owner_id"
const val PASSWORD = "password"
const val PATH = "path"
const val PEER = "peer"
const val PEER_ID = "peer_id"
const val PHOTOS = "photos"
const val PLACE = "place"
const val PLACE_TYPE = "place_type"
const val POLL = "poll"
const val POSITION = "position"
const val POST = "post"
const val POST_ID = "post_id"
const val PRIVACY = "privacy"
const val PTR = "ptr"
const val QUERY = "query"
const val READONLY = "readonly"
const val REQUEST = "request"
const val SAVE = "save"
const val SCHOOL = "school"
const val SCHOOL_ID = "school_id"
const val SCHOOL_CLASS = "school_class"
const val SCHOOL_CLASS_ID = "school_class_id"
const val BODY = "body"
const val COMMENT = "comment"
const val ARTIST = "artist"
const val SCHOOL_ID = "school_id"
const val SECTION_ID = "section_id"
const val SELECTED = "selected"
const val SERVICE = "service"
const val STATUS = "status"
const val ERROR = "error"
const val COMMENTED = "commented"
const val FOCUS_TO = "focus_to"
const val MESSAGES = "messages"
const val MESSAGE = "message"
const val METHOD = "method"
const val PLACE_TYPE = "place_type"
const val INDEX = "index"
const val PEER = "peer"
const val SESSION_ID = "session_id"
const val POLL = "poll"
const val USER_IDS = "user_ids"
const val MAX_COUNT = "max_count"
const val BUNDLE = "bundle"
const val ATTRS = "attrs"
const val SUBTITLE = "subtitle"
const val SETTINGS = "settings"
const val BANNED = "banned"
const val SHUFFLE_MODE = "shuffle_mode"
const val SOURCE = "source"
const val SOURCES = "sources"
const val MANAGER = "manager"
const val STACK_TRACE = "stack_trace"
const val STATUS = "status"
const val STORY = "story"
const val MARKET = "market"
const val SAVE = "save"
const val NEW = "new"
const val OLD = "old"
const val INCOMING = "incoming"
const val OUTGOING = "outgoing"
const val SUBTITLE = "subtitle"
const val TAB = "tab"
const val TITLE = "title"
const val TOKEN = "token"
const val TOP = "top"
const val READONLY = "readonly"
const val INVERT = "invert"
const val PTR = "ptr"
const val REQUEST = "request"
const val PATH = "path"
const val EXT = "ext"
const val STACK_TRACE = "stack_trace"
const val IS_OUT_OF_MEMORY = "is_out_of_memory"
const val IS_BOARD = "is_board"
const val ANSWER = "answer"
const val SELECTED = "selected"
const val SECTION_ID = "section_id"
const val QUERY = "query"
const val TWO_FA = "two_fa"
const val TYPE = "type"
const val UNIVERSITY = "university"
const val UNIVERSITY_ID = "university_id"
const val URL = "url"
const val USER = "user"
const val USERS = "users"
const val USER_ID = "user_id"
const val VIDEO = "video"
const val VIDEOS = "videos"
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,26 @@ abstract class AbsAdapter<T>(name: String) : KSerializer<T> {
}
}

fun getFirstLong(json: JsonObject?, fallback: Long, vararg names: String): Long {
contract {
returns(true) implies (json != null)
}
json ?: return fallback
return try {
for (name in names) {
val element = json[name]
if (element is JsonPrimitive) {
return element.longOrNull ?: fallback
}
}
fallback
} catch (e: Exception) {
if (Constants.IS_DEBUG) {
e.printStackTrace()
}
fallback
}
}

@JvmOverloads
fun optLong(array: JsonArray?, index: Int, fallback: Long = 0L): Long {
Expand Down Expand Up @@ -345,7 +365,6 @@ abstract class AbsAdapter<T>(name: String) : KSerializer<T> {
}
}


fun optIntArray(root: JsonObject?, name: String, fallback: IntArray?): IntArray? {
contract {
returns(true) implies (root != null)
Expand All @@ -364,7 +383,6 @@ abstract class AbsAdapter<T>(name: String) : KSerializer<T> {
}
}


fun optIntArray(array: JsonArray?, index: Int, fallback: IntArray?): IntArray? {
contract {
returns(true) implies (array != null)
Expand All @@ -386,6 +404,57 @@ abstract class AbsAdapter<T>(name: String) : KSerializer<T> {
}
}

fun optLongArray(root: JsonObject?, name: String, fallback: LongArray?): LongArray? {
contract {
returns(true) implies (root != null)
}
root ?: return fallback
return try {
val element = root[name]
if (!checkArray(element)) {
fallback
} else parseLongArray(element.jsonArray)
} catch (e: Exception) {
if (Constants.IS_DEBUG) {
e.printStackTrace()
}
fallback
}
}

fun optLongArray(array: JsonArray?, index: Int, fallback: LongArray?): LongArray? {
contract {
returns(true) implies (array != null)
}
array ?: return fallback
return try {
if (index < 0 || index >= array.size) {
return fallback
}
val array_r = array[index]
if (!checkArray(array_r)) {
fallback
} else parseLongArray(array_r.jsonArray)
} catch (e: Exception) {
if (Constants.IS_DEBUG) {
e.printStackTrace()
}
fallback
}
}

private fun parseLongArray(array: JsonArray?): LongArray {
contract {
returns(true) implies (array != null)
}
array ?: return LongArray(0)
val list = LongArray(array.size)
for (i in 0 until array.size) {
list[i] = array[i].jsonPrimitive.long
}
return list
}

private fun parseIntArray(array: JsonArray?): IntArray {
contract {
returns(true) implies (array != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.ragnarok.fenrir.api.adapters

import dev.ragnarok.fenrir.api.model.*
import dev.ragnarok.fenrir.api.model.interfaces.VKApiAttachment
import dev.ragnarok.fenrir.kJson
import dev.ragnarok.fenrir.nonNullNoEmpty
import dev.ragnarok.fenrir.util.Utils
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dev.ragnarok.fenrir.api.adapters

import dev.ragnarok.fenrir.api.adapters.AttachmentsDtoAdapter.Companion.parse
import dev.ragnarok.fenrir.api.model.VKApiAttachment
import dev.ragnarok.fenrir.api.model.VKApiAttachments
import dev.ragnarok.fenrir.api.model.VKApiNotSupported
import dev.ragnarok.fenrir.api.model.interfaces.VKApiAttachment
import dev.ragnarok.fenrir.util.serializeble.json.JsonElement
import dev.ragnarok.fenrir.util.serializeble.json.jsonObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AudioPlaylistDtoAdapter : AbsAdapter<VKApiAudioPlaylist>("VKApiAudioPlayli
album.title = optString(root, "title")
album.access_key = optString(root, "access_key")
album.description = optString(root, "description")
album.update_time = optInt(root, "update_time").toLong()
album.update_time = optLong(root, "update_time")
album.Year = optInt(root, "year")
if (hasArray(root, "genres")) {
val build = StringBuilder()
Expand Down Expand Up @@ -69,4 +69,4 @@ class AudioPlaylistDtoAdapter : AbsAdapter<VKApiAudioPlaylist>("VKApiAudioPlayli
companion object {
private val TAG = AudioPlaylistDtoAdapter::class.java.simpleName
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ class GroupSettingsAdapter : AbsAdapter<GroupSettingsDto>("GroupSettingsDto") {
dto.title = optString(root, "title")
dto.description = optString(root, "description")
dto.address = optString(root, "address")
if (hasObject(root, "place")) {
dto.place = root["place"]?.let {
kJson.decodeFromJsonElement(GroupSettingsDto.Place.serializer(), it)
}
}
dto.country_id = optInt(root, "country_id")
dto.city_id = optInt(root, "city_id")
dto.wall = optInt(root, "wall")
Expand Down Expand Up @@ -81,4 +76,4 @@ class GroupSettingsAdapter : AbsAdapter<GroupSettingsDto>("GroupSettingsDto") {
companion object {
private val TAG = GroupSettingsAdapter::class.java.simpleName
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ class LongpollUpdateAdapter : AbsAdapter<AbsLongpollEvent?>("AbsLongpollEvent?")
val u = UserIsOnlineUpdate()
u.userId = -optInt(array, 1)
u.platform = optInt(array, 2)
u.timestamp = optInt(array, 3)
u.timestamp = optLong(array, 3)
u.app_id = optInt(array, 4)
return u
}
AbsLongpollEvent.ACTION_USER_IS_OFFLINE -> {
val u1 = UserIsOfflineUpdate()
u1.userId = -optInt(array, 1)
u1.isTimeout = optInt(array, 2) != 0
u1.timestamp = optInt(array, 3)
u1.timestamp = optLong(array, 3)
u1.app_id = optInt(array, 4)
return u1
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.ragnarok.fenrir.api.adapters

import dev.ragnarok.fenrir.api.model.*
import dev.ragnarok.fenrir.api.model.interfaces.VKApiAttachment
import dev.ragnarok.fenrir.api.util.VKStringUtils
import dev.ragnarok.fenrir.kJson
import dev.ragnarok.fenrir.orZero
Expand Down
Loading

0 comments on commit 2f99cd9

Please sign in to comment.