2020-11-05 14:27:45 +00:00
package dev.inmo.tgbotapi.requests.send
2022-05-01 16:13:40 +00:00
import dev.inmo.tgbotapi.abstracts.TextedOutput
import dev.inmo.tgbotapi.abstracts.types.MessageAction
import dev.inmo.tgbotapi.abstracts.types.ProtectContent
2020-11-05 14:27:45 +00:00
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest
import dev.inmo.tgbotapi.types.*
2022-05-01 14:36:07 +00:00
import dev.inmo.tgbotapi.types.message.textsources.TextSource
2022-05-01 14:43:03 +00:00
import dev.inmo.tgbotapi.types.message.ParseMode
import dev.inmo.tgbotapi.types.message.parseModeField
2020-11-05 14:27:45 +00:00
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
2022-05-01 14:36:07 +00:00
import dev.inmo.tgbotapi.types.message.*
import dev.inmo.tgbotapi.types.message.RawMessageEntity
import dev.inmo.tgbotapi.types.message.toRawMessageEntities
2021-08-08 12:00:42 +00:00
import dev.inmo.tgbotapi.utils.extensions.makeString
2020-11-05 14:27:45 +00:00
import kotlinx.serialization.*
2022-07-10 18:45:11 +00:00
// TODO:: Swap fromChatId and toChatId for more correct order of parameters
2022-07-10 18:26:57 +00:00
const val OrderChangingDeprecationWarn = " The order of parameters in this factory will be changed soon. To avoid unexpected behaviour, swap message id and target chat id parameters "
2020-11-05 14:27:45 +00:00
fun CopyMessage (
toChatId : ChatIdentifier ,
2022-08-04 12:09:25 +00:00
fromChatId : ChatIdentifier ,
2020-11-05 14:27:45 +00:00
messageId : MessageIdentifier ,
text : String ? = null ,
parseMode : ParseMode ? = null ,
disableNotification : Boolean = false ,
2022-01-01 14:13:22 +00:00
protectContent : Boolean = false ,
2020-11-05 14:27:45 +00:00
replyToMessageId : MessageIdentifier ? = null ,
2020-11-05 15:33:11 +00:00
allowSendingWithoutReply : Boolean ? = null ,
2020-11-05 14:27:45 +00:00
replyMarkup : KeyboardMarkup ? = null
2022-07-10 18:26:57 +00:00
) = CopyMessage (
toChatId ,
fromChatId ,
messageId ,
text ,
parseMode ,
null ,
disableNotification ,
protectContent ,
replyToMessageId ,
allowSendingWithoutReply ,
replyMarkup
)
2020-11-05 14:27:45 +00:00
fun CopyMessage (
toChatId : ChatIdentifier ,
2022-08-04 12:09:25 +00:00
fromChatId : ChatIdentifier ,
2020-11-05 14:27:45 +00:00
messageId : MessageIdentifier ,
2021-05-29 09:34:14 +00:00
entities : List < TextSource > ,
2020-11-05 14:27:45 +00:00
disableNotification : Boolean = false ,
2022-01-01 14:13:22 +00:00
protectContent : Boolean = false ,
2020-11-05 14:27:45 +00:00
replyToMessageId : MessageIdentifier ? = null ,
2020-11-05 15:33:11 +00:00
allowSendingWithoutReply : Boolean ? = null ,
2020-11-05 14:27:45 +00:00
replyMarkup : KeyboardMarkup ? = null
2021-05-29 10:02:55 +00:00
) = CopyMessage (
2022-07-10 18:26:57 +00:00
toChatId ,
2021-05-29 10:02:55 +00:00
fromChatId ,
2022-07-10 18:26:57 +00:00
messageId ,
entities . makeString ( ) ,
null ,
entities . toRawMessageEntities ( ) ,
disableNotification ,
protectContent ,
replyToMessageId ,
allowSendingWithoutReply ,
replyMarkup
)
fun CopyMessage (
fromChatId : ChatIdentifier ,
messageId : MessageIdentifier ,
toChatId : ChatIdentifier ,
text : String ? = null ,
parseMode : ParseMode ? = null ,
disableNotification : Boolean = false ,
protectContent : Boolean = false ,
replyToMessageId : MessageIdentifier ? = null ,
allowSendingWithoutReply : Boolean ? = null ,
replyMarkup : KeyboardMarkup ? = null
) = CopyMessage (
2021-05-29 10:02:55 +00:00
toChatId ,
2022-07-10 18:26:57 +00:00
fromChatId ,
messageId ,
text ,
parseMode ,
null ,
disableNotification ,
protectContent ,
replyToMessageId ,
allowSendingWithoutReply ,
replyMarkup
)
fun CopyMessage (
fromChatId : ChatIdentifier ,
messageId : MessageIdentifier ,
toChatId : ChatIdentifier ,
entities : List < TextSource > ,
disableNotification : Boolean = false ,
protectContent : Boolean = false ,
replyToMessageId : MessageIdentifier ? = null ,
allowSendingWithoutReply : Boolean ? = null ,
replyMarkup : KeyboardMarkup ? = null
) = CopyMessage (
toChatId ,
fromChatId ,
2021-05-29 10:02:55 +00:00
messageId ,
entities . makeString ( ) ,
null ,
entities . toRawMessageEntities ( ) ,
disableNotification ,
2022-01-01 14:13:22 +00:00
protectContent ,
2021-05-29 10:02:55 +00:00
replyToMessageId ,
allowSendingWithoutReply ,
replyMarkup
)
2020-11-05 14:27:45 +00:00
@Serializable
data class CopyMessage internal constructor (
@SerialName ( chatIdField )
val toChatId : ChatIdentifier ,
2022-07-10 18:26:57 +00:00
@SerialName ( fromChatIdField )
val fromChatId : ChatIdentifier ,
2020-11-05 14:27:45 +00:00
@SerialName ( messageIdField )
override val messageId : MessageIdentifier ,
@SerialName ( captionField )
override val text : String ? = null ,
@SerialName ( parseModeField )
override val parseMode : ParseMode ? = null ,
@SerialName ( captionEntitiesField )
private val rawEntities : List < RawMessageEntity > ? = null ,
@SerialName ( disableNotificationField )
override val disableNotification : Boolean = false ,
2022-01-01 14:13:22 +00:00
@SerialName ( protectContentField )
override val protectContent : Boolean = false ,
2020-11-05 14:27:45 +00:00
@SerialName ( replyToMessageIdField )
override val replyToMessageId : MessageIdentifier ? = null ,
2020-11-05 15:33:11 +00:00
@SerialName ( allowSendingWithoutReplyField )
override val allowSendingWithoutReply : Boolean ? = null ,
2020-11-05 14:27:45 +00:00
@SerialName ( replyMarkupField )
override val replyMarkup : KeyboardMarkup ? = null
2020-11-05 19:14:48 +00:00
) : SimpleRequest < MessageIdentifier > ,
ReplyingMarkupSendMessageRequest < MessageIdentifier > ,
2020-11-05 14:27:45 +00:00
MessageAction ,
2022-01-01 14:13:22 +00:00
TextedOutput ,
ProtectContent {
2020-11-05 14:27:45 +00:00
override val chatId : ChatIdentifier
get ( ) = fromChatId
2021-04-29 05:52:38 +00:00
override val textSources : List < TextSource > ? by lazy {
2021-04-28 13:54:57 +00:00
rawEntities ?. asTextSources ( text ?: return @lazy null )
2020-11-05 14:27:45 +00:00
}
override fun method ( ) : String = " copyMessage "
2020-11-05 19:14:48 +00:00
override val resultDeserializer : DeserializationStrategy < MessageIdentifier >
get ( ) = MessageIdSerializer
2020-11-05 14:27:45 +00:00
override val requestSerializer : SerializationStrategy < * >
get ( ) = serializer ( )
}