1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-25 03:28:44 +00:00

Merge pull request #25 from InsanusMokrassar/0.12.3

0.12.3
This commit is contained in:
InsanusMokrassar 2019-03-21 20:27:57 -05:00 committed by GitHub
commit d3a6978f4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 33 additions and 52 deletions

View File

@ -38,6 +38,17 @@
* `UpdatesFilter` and other objects now work with `UpdateReceiver<Update>` as common supertype
for receivers.
### 0.12.3 Cleaning
* Refactor, optimizing and cleaning of code
* Removed deprecated method `T#toJsonWithoutNulls()`
* Renamed instances of `MediaGroupMessage`s and refactored their interfaces. `ChannelMediaGroupMessage`
will not contain `user` field (but `CommonMediaGroupMessage` will have)
* Now `MediaCollectionContent` is `MediaContent` (classes of this interface must choose best
media for present out)
* `PhotoContent` now choose biggest photo size from its collection as `media`
* Fix in order of media group messages which was received by webhooks
## 0.11.0
* Kotlin `1.3.11` -> `1.3.21`

View File

@ -1,4 +1,4 @@
project.version = "0.12.2"
project.version = "0.12.3"
project.group = "com.github.insanusmokrassar"
buildscript {

View File

@ -7,4 +7,7 @@ ktor_version=1.1.2
gradle_bintray_plugin_version=1.8.4
project_public_name=Telegram Bot API
project_public_description=It is one more project which wish to be useful and full Telegram Bots API bridge for Kotlin
disableImplicitReflectionSerializerAnnotation=-Xexperimental=kotlinx.serialization.ImplicitReflectionSerializer

View File

@ -1,26 +1,6 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
def pomConfig = {
licenses {
license {
name "The Apache Software License, Version 2.0"
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "repo"
}
}
developers {
developer {
name "Ovsiannikov Aleksei"
email "ovsyannikov.alexey95@gmail.com"
}
}
scm {
url "https://github.com/InsanusMokrassar/${project.name}"
}
}
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
@ -45,8 +25,8 @@ publishing {
pom.withXml {
asNode().children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
name 'Telegram Bot API'
description 'It is one more project which wish to be useful and full Telegram Bots API bridge for Kotlin'
name "${project_public_name}"
description "${project_public_description}"
url "https://insanusmokrassar.github.io/${project.name}"
scm {

View File

@ -11,10 +11,8 @@ import io.ktor.client.request.forms.MultiPartFormDataContent
import io.ktor.client.request.forms.formData
import io.ktor.client.request.url
import io.ktor.http.*
import kotlinx.serialization.ImplicitReflectionSerializer
class MultipartRequestCallFactory : KtorCallFactory {
@ImplicitReflectionSerializer
override suspend fun <T: Any> prepareCall(
client: HttpClient,
baseUrl: String,

View File

@ -11,10 +11,8 @@ import io.ktor.client.request.url
import io.ktor.http.ContentType
import io.ktor.http.HttpMethod
import io.ktor.http.content.TextContent
import kotlinx.serialization.ImplicitReflectionSerializer
class SimpleRequestCallFactory : KtorCallFactory {
@ImplicitReflectionSerializer
override suspend fun <T: Any> prepareCall(
client: HttpClient,
baseUrl: String,

View File

@ -1,13 +1,11 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.common
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import kotlinx.serialization.ImplicitReflectionSerializer
import kotlinx.serialization.json.JsonObject
data class CommonMultipartFileRequest<T: Any>(
val data: Request<T>,
override val mediaMap: Map<String, MultipartFile>
) : MultipartRequest<T>, Request<T> by data {
@ImplicitReflectionSerializer
override val paramsJson: JsonObject = data.json()
}

View File

@ -2,7 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartRequest
import kotlinx.serialization.ImplicitReflectionSerializer
import kotlinx.serialization.KSerializer
import kotlinx.serialization.json.JsonObject
@ -15,7 +14,6 @@ class MultipartRequestImpl<D: DataRequest<R>, F: Files, R: Any>(
) : MultipartRequest<R> {
override fun method(): String = data.method()
override fun resultSerializer(): KSerializer<R> = data.resultSerializer()
@ImplicitReflectionSerializer
override val paramsJson: JsonObject = data.json()
override val mediaMap: Map<String, MultipartFile> = files
}

View File

@ -8,7 +8,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Messag
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent
import org.joda.time.DateTime
data class MediaGroupMessage(
data class ChannelMediaGroupMessage(
override val messageId: MessageIdentifier,
override val chat: Chat,
override val date: DateTime,
@ -17,4 +17,4 @@ data class MediaGroupMessage(
override val editDate: DateTime?,
override val forwarded: ForwardedMessage?,
override val replyTo: Message?
) : Message, MediaGroupMessage
) : MediaGroupMessage

View File

@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent
import org.joda.time.DateTime
@ -17,4 +16,4 @@ data class CommonMediaGroupMessage(
override val editDate: DateTime?,
override val forwarded: ForwardedMessage?,
override val replyTo: Message?
) : Message, MediaGroupMessage, FromUserMessage
) : MediaGroupMessage, FromUserMessage

View File

@ -210,7 +210,7 @@ data class RawMessage(
content ->
media_group_id ?.let {
when (from) {
null -> MediaGroupMessage(
null -> ChannelMediaGroupMessage(
messageId,
chat,
date.asDate,

View File

@ -2,6 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstrac
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.TelegramMediaFile
interface MediaCollectionContent<T: TelegramMediaFile>: MessageContent {
val media: List<T>
interface MediaCollectionContent<T: TelegramMediaFile>: MessageContent, MediaContent<T> {
val mediaCollection: List<T>
}

View File

@ -16,10 +16,12 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstract
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaptions
data class PhotoContent(
override val media: List<PhotoSize>,
override val mediaCollection: List<PhotoSize>,
override val caption: String? = null,
override val captionEntities: List<MessageEntity> = emptyList()
) : MediaCollectionContent<PhotoSize>, CaptionedMediaContent, MediaGroupContent {
override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content")
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
@ -27,7 +29,7 @@ data class PhotoContent(
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendPhoto(
chatId,
media.biggest() ?.fileId ?: throw IllegalStateException("Empty list of media"),
media.fileId,
toMarkdownCaptions().firstOrNull(),
MarkdownParseMode,
disableNotification,
@ -36,7 +38,7 @@ data class PhotoContent(
)
override fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = InputMediaPhoto(
media.biggest() ?.fileId ?: throw IllegalStateException("Can't locate any photo size for this content"),
media.fileId,
toMarkdownCaptions().firstOrNull(),
MarkdownParseMode
)

View File

@ -5,11 +5,12 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
fun List<BaseMessageUpdate>.toMediaGroupUpdate(): MediaGroupUpdate? = (this as? MediaGroupUpdate) ?: let {
val resultList = sortedBy { it.updateId }
when (first()) {
is MessageUpdate -> MessageMediaGroupUpdate(this)
is EditMessageUpdate -> EditMessageMediaGroupUpdate(this)
is ChannelPostUpdate -> ChannelPostMediaGroupUpdate(this)
is EditChannelPostUpdate -> EditChannelPostMediaGroupUpdate(this)
is MessageUpdate -> MessageMediaGroupUpdate(resultList)
is EditMessageUpdate -> EditMessageMediaGroupUpdate(resultList)
is ChannelPostUpdate -> ChannelPostMediaGroupUpdate(resultList)
is EditChannelPostUpdate -> EditChannelPostMediaGroupUpdate(resultList)
else -> null
}
}

View File

@ -1,15 +1,8 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
import kotlinx.serialization.ImplicitReflectionSerializer
import kotlinx.serialization.KSerializer
import kotlinx.serialization.json.*
@Deprecated("This method can throw exceptions")
@ImplicitReflectionSerializer
inline fun <reified T: Any> T.toJsonWithoutNulls(): JsonObject = Json.nonstrict.toJson(
this
).jsonObject.withoutNulls()
inline fun <reified T: Any> T.toJsonWithoutNulls(serializer: KSerializer<T>): JsonObject = toJson(serializer).withoutNulls()
inline fun <reified T: Any> T.toJson(serializer: KSerializer<T>): JsonObject = Json.nonstrict.toJson(