1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-02 07:55:25 +00:00
tgbotapi/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/FlowsUpdatesFilter.kt

74 lines
5.0 KiB
Kotlin
Raw Normal View History

2019-05-10 03:54:57 +00:00
package com.github.insanusmokrassar.TelegramBotAPI.updateshandlers
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
2020-03-17 11:16:14 +00:00
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
2019-05-10 03:54:57 +00:00
import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.asFlow
2020-05-16 16:02:57 +00:00
@Suppress("EXPERIMENTAL_API_USAGE")
2019-05-10 03:54:57 +00:00
private fun <T> BroadcastChannel<T>.createUpdateReceiver(): UpdateReceiver<T> = ::send
2020-05-16 16:02:57 +00:00
@Suppress("EXPERIMENTAL_API_USAGE", "unused")
class FlowsUpdatesFilter(
2020-05-16 16:02:57 +00:00
broadcastChannelsSize: Int = 64
2020-03-17 11:16:14 +00:00
): UpdatesFilter {
private val messageChannel: BroadcastChannel<MessageUpdate> = BroadcastChannel(broadcastChannelsSize)
private val messageMediaGroupChannel: BroadcastChannel<MessageMediaGroupUpdate> = BroadcastChannel(broadcastChannelsSize)
private val editedMessageChannel: BroadcastChannel<EditMessageUpdate> = BroadcastChannel(broadcastChannelsSize)
private val editedMessageMediaGroupChannel: BroadcastChannel<EditMessageMediaGroupUpdate> = BroadcastChannel(broadcastChannelsSize)
private val channelPostChannel: BroadcastChannel<ChannelPostUpdate> = BroadcastChannel(broadcastChannelsSize)
private val channelPostMediaGroupChannel: BroadcastChannel<ChannelPostMediaGroupUpdate> = BroadcastChannel(broadcastChannelsSize)
private val editedChannelPostChannel: BroadcastChannel<EditChannelPostUpdate> = BroadcastChannel(broadcastChannelsSize)
private val editedChannelPostMediaGroupChannel: BroadcastChannel<EditChannelPostMediaGroupUpdate> = BroadcastChannel(broadcastChannelsSize)
private val chosenInlineResultChannel: BroadcastChannel<ChosenInlineResultUpdate> = BroadcastChannel(broadcastChannelsSize)
private val inlineQueryChannel: BroadcastChannel<InlineQueryUpdate> = BroadcastChannel(broadcastChannelsSize)
private val callbackQueryChannel: BroadcastChannel<CallbackQueryUpdate> = BroadcastChannel(broadcastChannelsSize)
private val shippingQueryChannel: BroadcastChannel<ShippingQueryUpdate> = BroadcastChannel(broadcastChannelsSize)
private val preCheckoutQueryChannel: BroadcastChannel<PreCheckoutQueryUpdate> = BroadcastChannel(broadcastChannelsSize)
private val pollChannel: BroadcastChannel<PollUpdate> = BroadcastChannel(broadcastChannelsSize)
2020-03-22 11:21:01 +00:00
private val pollAnswerChannel: BroadcastChannel<PollAnswerUpdate> = BroadcastChannel(broadcastChannelsSize)
private val unknownUpdateChannel: BroadcastChannel<Update> = BroadcastChannel(broadcastChannelsSize)
2019-05-10 03:54:57 +00:00
2020-03-17 11:16:14 +00:00
override val allowedUpdates: List<String>
get() = filter.allowedUpdates
override val asUpdateReceiver: UpdateReceiver<Update>
get() = filter.asUpdateReceiver
val filter = SimpleUpdatesFilter(
2019-05-10 03:54:57 +00:00
messageChannel.createUpdateReceiver(),
messageMediaGroupChannel.createUpdateReceiver(),
editedMessageChannel.createUpdateReceiver(),
editedMessageMediaGroupChannel.createUpdateReceiver(),
channelPostChannel.createUpdateReceiver(),
channelPostMediaGroupChannel.createUpdateReceiver(),
editedChannelPostChannel.createUpdateReceiver(),
editedChannelPostMediaGroupChannel.createUpdateReceiver(),
chosenInlineResultChannel.createUpdateReceiver(),
inlineQueryChannel.createUpdateReceiver(),
callbackQueryChannel.createUpdateReceiver(),
2019-05-10 03:54:57 +00:00
shippingQueryChannel.createUpdateReceiver(),
preCheckoutQueryChannel.createUpdateReceiver(),
2020-03-22 11:21:01 +00:00
pollChannel.createUpdateReceiver(),
pollAnswerChannel.createUpdateReceiver(),
unknownUpdateChannel.createUpdateReceiver()
2019-05-10 03:54:57 +00:00
)
val messageFlow: Flow<MessageUpdate> = messageChannel.asFlow()
val messageMediaGroupFlow: Flow<MessageMediaGroupUpdate> = messageMediaGroupChannel.asFlow()
val editedMessageFlow: Flow<EditMessageUpdate> = editedMessageChannel.asFlow()
val editedMessageMediaGroupFlow: Flow<EditMessageMediaGroupUpdate> = editedMessageMediaGroupChannel.asFlow()
val channelPostFlow: Flow<ChannelPostUpdate> = channelPostChannel.asFlow()
val channelPostMediaGroupFlow: Flow<ChannelPostMediaGroupUpdate> = channelPostMediaGroupChannel.asFlow()
val editedChannelPostFlow: Flow<EditChannelPostUpdate> = editedChannelPostChannel.asFlow()
val editedChannelPostMediaGroupFlow: Flow<EditChannelPostMediaGroupUpdate> = editedChannelPostMediaGroupChannel.asFlow()
val chosenInlineResultFlow: Flow<ChosenInlineResultUpdate> = chosenInlineResultChannel.asFlow()
val inlineQueryFlow: Flow<InlineQueryUpdate> = inlineQueryChannel.asFlow()
val callbackQueryFlow: Flow<CallbackQueryUpdate> = callbackQueryChannel.asFlow()
val shippingQueryFlow: Flow<ShippingQueryUpdate> = shippingQueryChannel.asFlow()
val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate> = preCheckoutQueryChannel.asFlow()
val pollFlow: Flow<PollUpdate> = pollChannel.asFlow()
2020-03-22 11:21:01 +00:00
val pollAnswerFlow: Flow<PollAnswerUpdate> = pollAnswerChannel.asFlow()
val unknownUpdateTypeFlow: Flow<Update> = unknownUpdateChannel.asFlow()
2019-05-10 03:54:57 +00:00
}