mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
UpdatesFilter now is interface
This commit is contained in:
parent
244a1e5175
commit
ba2c4cbb30
@ -15,6 +15,10 @@
|
|||||||
* `UpdateReceiver` was replaced to the package `com.github.insanusmokrassar.TelegramBotAPI.updateshandlers`
|
* `UpdateReceiver` was replaced to the package `com.github.insanusmokrassar.TelegramBotAPI.updateshandlers`
|
||||||
* All functions inside `com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.UpdatesPolling` are deprecated
|
* All functions inside `com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.UpdatesPolling` are deprecated
|
||||||
and will be removed in some soon versions. Their replacement are able inside `TelegramBotAPI-extensions-api`
|
and will be removed in some soon versions. Their replacement are able inside `TelegramBotAPI-extensions-api`
|
||||||
|
* `UpdatesFilter` is interface for now
|
||||||
|
* Previous `UpdatesFilter` class was renamed to `SimpleUpdatesFilter` and for backward compatibility was added
|
||||||
|
builder function `UpdatesFilter`, which will be removed in near releases
|
||||||
|
* `FlowsUpdatesFilter` now implements `UpdatesFilter`
|
||||||
* `TelegramBotAPI-extensions-api`:
|
* `TelegramBotAPI-extensions-api`:
|
||||||
* All functions from `com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.UpdatesPolling` now available
|
* All functions from `com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.UpdatesPolling` now available
|
||||||
in package `com.github.insanusmokrassar.TelegramBotAPI.extensions.api.updates.UpdatesPolling`
|
in package `com.github.insanusmokrassar.TelegramBotAPI.extensions.api.updates.UpdatesPolling`
|
||||||
|
@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.updateshandlers
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||||
import kotlinx.coroutines.channels.BroadcastChannel
|
import kotlinx.coroutines.channels.BroadcastChannel
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@ -11,7 +12,7 @@ private fun <T> BroadcastChannel<T>.createUpdateReceiver(): UpdateReceiver<T> =
|
|||||||
|
|
||||||
class FlowsUpdatesFilter(
|
class FlowsUpdatesFilter(
|
||||||
broadcastChannelsSize: Int = Channel.CONFLATED
|
broadcastChannelsSize: Int = Channel.CONFLATED
|
||||||
) {
|
): UpdatesFilter {
|
||||||
private val messageChannel: BroadcastChannel<MessageUpdate> = BroadcastChannel(broadcastChannelsSize)
|
private val messageChannel: BroadcastChannel<MessageUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||||
private val messageMediaGroupChannel: BroadcastChannel<MessageMediaGroupUpdate> = BroadcastChannel(broadcastChannelsSize)
|
private val messageMediaGroupChannel: BroadcastChannel<MessageMediaGroupUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||||
private val editedMessageChannel: BroadcastChannel<EditMessageUpdate> = BroadcastChannel(broadcastChannelsSize)
|
private val editedMessageChannel: BroadcastChannel<EditMessageUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||||
@ -27,7 +28,12 @@ class FlowsUpdatesFilter(
|
|||||||
private val preCheckoutQueryChannel: BroadcastChannel<PreCheckoutQueryUpdate> = BroadcastChannel(broadcastChannelsSize)
|
private val preCheckoutQueryChannel: BroadcastChannel<PreCheckoutQueryUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||||
private val pollChannel: BroadcastChannel<PollUpdate> = BroadcastChannel(broadcastChannelsSize)
|
private val pollChannel: BroadcastChannel<PollUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||||
|
|
||||||
val filter = UpdatesFilter(
|
override val allowedUpdates: List<String>
|
||||||
|
get() = filter.allowedUpdates
|
||||||
|
override val asUpdateReceiver: UpdateReceiver<Update>
|
||||||
|
get() = filter.asUpdateReceiver
|
||||||
|
|
||||||
|
val filter = SimpleUpdatesFilter(
|
||||||
messageChannel.createUpdateReceiver(),
|
messageChannel.createUpdateReceiver(),
|
||||||
messageMediaGroupChannel.createUpdateReceiver(),
|
messageMediaGroupChannel.createUpdateReceiver(),
|
||||||
editedMessageChannel.createUpdateReceiver(),
|
editedMessageChannel.createUpdateReceiver(),
|
||||||
|
@ -6,7 +6,57 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UnknownUpdateType
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UnknownUpdateType
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||||
|
|
||||||
data class UpdatesFilter(
|
typealias UpdateReceiver<T> = suspend (T) -> Unit
|
||||||
|
|
||||||
|
interface UpdatesFilter {
|
||||||
|
val asUpdateReceiver: UpdateReceiver<Update>
|
||||||
|
val allowedUpdates: List<String>
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"It is builder function for SimpleUpdatesFilter",
|
||||||
|
ReplaceWith(
|
||||||
|
"SimpleUpdatesFilter",
|
||||||
|
"com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.SimpleUpdatesFilter"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
fun UpdatesFilter(
|
||||||
|
messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
||||||
|
messageMediaGroupCallback: UpdateReceiver<MessageMediaGroupUpdate>? = null,
|
||||||
|
editedMessageCallback: UpdateReceiver<EditMessageUpdate>? = null,
|
||||||
|
editedMessageMediaGroupCallback: UpdateReceiver<EditMessageMediaGroupUpdate>? = null,
|
||||||
|
channelPostCallback: UpdateReceiver<ChannelPostUpdate>? = null,
|
||||||
|
channelPostMediaGroupCallback: UpdateReceiver<ChannelPostMediaGroupUpdate>? = null,
|
||||||
|
editedChannelPostCallback: UpdateReceiver<EditChannelPostUpdate>? = null,
|
||||||
|
editedChannelPostMediaGroupCallback: UpdateReceiver<EditChannelPostMediaGroupUpdate>? = null,
|
||||||
|
chosenInlineResultCallback: UpdateReceiver<ChosenInlineResultUpdate>? = null,
|
||||||
|
inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
|
||||||
|
callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
|
||||||
|
shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
|
||||||
|
preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
|
||||||
|
pollUpdateCallback: UpdateReceiver<PollUpdate>? = null,
|
||||||
|
pollAnswerUpdateCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
||||||
|
unknownUpdateTypeCallback: UpdateReceiver<UnknownUpdateType>? = null
|
||||||
|
) = SimpleUpdatesFilter(
|
||||||
|
messageCallback,
|
||||||
|
messageMediaGroupCallback,
|
||||||
|
editedMessageCallback,
|
||||||
|
editedMessageMediaGroupCallback,
|
||||||
|
channelPostCallback,
|
||||||
|
channelPostMediaGroupCallback,
|
||||||
|
editedChannelPostCallback,
|
||||||
|
editedChannelPostMediaGroupCallback,
|
||||||
|
chosenInlineResultCallback,
|
||||||
|
inlineQueryCallback,
|
||||||
|
callbackQueryCallback,
|
||||||
|
shippingQueryCallback,
|
||||||
|
preCheckoutQueryCallback,
|
||||||
|
pollUpdateCallback,
|
||||||
|
pollAnswerUpdateCallback,
|
||||||
|
unknownUpdateTypeCallback
|
||||||
|
)
|
||||||
|
|
||||||
|
data class SimpleUpdatesFilter(
|
||||||
private val messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
private val messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
||||||
private val messageMediaGroupCallback: UpdateReceiver<MessageMediaGroupUpdate>? = null,
|
private val messageMediaGroupCallback: UpdateReceiver<MessageMediaGroupUpdate>? = null,
|
||||||
private val editedMessageCallback: UpdateReceiver<EditMessageUpdate>? = null,
|
private val editedMessageCallback: UpdateReceiver<EditMessageUpdate>? = null,
|
||||||
@ -23,9 +73,9 @@ data class UpdatesFilter(
|
|||||||
private val pollUpdateCallback: UpdateReceiver<PollUpdate>? = null,
|
private val pollUpdateCallback: UpdateReceiver<PollUpdate>? = null,
|
||||||
private val pollAnswerUpdateCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
private val pollAnswerUpdateCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
||||||
private val unknownUpdateTypeCallback: UpdateReceiver<UnknownUpdateType>? = null
|
private val unknownUpdateTypeCallback: UpdateReceiver<UnknownUpdateType>? = null
|
||||||
) {
|
) : UpdatesFilter {
|
||||||
val asUpdateReceiver: UpdateReceiver<Update> = this::invoke
|
override val asUpdateReceiver: UpdateReceiver<Update> = this::invoke
|
||||||
val allowedUpdates = listOfNotNull(
|
override val allowedUpdates = listOfNotNull(
|
||||||
(messageCallback ?: messageMediaGroupCallback) ?.let { UPDATE_MESSAGE },
|
(messageCallback ?: messageMediaGroupCallback) ?.let { UPDATE_MESSAGE },
|
||||||
(editedMessageCallback ?: editedMessageMediaGroupCallback) ?.let { UPDATE_EDITED_MESSAGE },
|
(editedMessageCallback ?: editedMessageMediaGroupCallback) ?.let { UPDATE_EDITED_MESSAGE },
|
||||||
(channelPostCallback ?: channelPostMediaGroupCallback) ?.let { UPDATE_CHANNEL_POST },
|
(channelPostCallback ?: channelPostMediaGroupCallback) ?.let { UPDATE_CHANNEL_POST },
|
||||||
@ -113,4 +163,3 @@ fun createSimpleUpdateFilter(
|
|||||||
pollAnswerUpdateCallback = pollAnswerCallback,
|
pollAnswerUpdateCallback = pollAnswerCallback,
|
||||||
unknownUpdateTypeCallback = unknownCallback
|
unknownUpdateTypeCallback = unknownCallback
|
||||||
)
|
)
|
||||||
typealias UpdateReceiver<T> = suspend (T) -> Unit
|
|
Loading…
Reference in New Issue
Block a user