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

41 lines
2.5 KiB
Kotlin
Raw Normal View History

2019-05-10 03:54:57 +00:00
package com.github.insanusmokrassar.TelegramBotAPI.updateshandlers
2020-06-27 03:43:24 +00:00
import com.github.insanusmokrassar.TelegramBotAPI.types.ALL_UPDATES_LIST
2019-05-10 03:54:57 +00:00
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
2020-07-02 10:15:06 +00:00
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UnknownUpdate
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
2019-05-10 03:54:57 +00:00
import kotlinx.coroutines.channels.BroadcastChannel
2020-06-27 03:43:24 +00:00
import kotlinx.coroutines.flow.*
2019-05-10 03:54:57 +00:00
2020-05-16 16:02:57 +00:00
@Suppress("EXPERIMENTAL_API_USAGE", "unused")
class FlowsUpdatesFilter(
2020-06-27 03:43:24 +00:00
broadcastChannelsSize: Int = 100
2020-03-17 11:16:14 +00:00
): UpdatesFilter {
2020-06-27 03:43:24 +00:00
private val updatesReceivingChannel = BroadcastChannel<Update>(broadcastChannelsSize)
@Suppress("MemberVisibilityCanBePrivate")
val allUpdatesFlow: Flow<Update> = updatesReceivingChannel.asFlow()
2019-05-10 03:54:57 +00:00
2020-03-17 11:16:14 +00:00
override val allowedUpdates: List<String>
2020-06-27 03:43:24 +00:00
get() = ALL_UPDATES_LIST
override val asUpdateReceiver: UpdateReceiver<Update> = {
updatesReceivingChannel.send(it)
}
2019-05-10 03:54:57 +00:00
2020-06-27 03:43:24 +00:00
val messageFlow: Flow<MessageUpdate> = allUpdatesFlow.filterIsInstance()
val messageMediaGroupFlow: Flow<MessageMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
val editedMessageFlow: Flow<EditMessageUpdate> = allUpdatesFlow.filterIsInstance()
val editedMessageMediaGroupFlow: Flow<EditMessageMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
val channelPostFlow: Flow<ChannelPostUpdate> = allUpdatesFlow.filterIsInstance()
val channelPostMediaGroupFlow: Flow<ChannelPostMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
val editedChannelPostFlow: Flow<EditChannelPostUpdate> = allUpdatesFlow.filterIsInstance()
val editedChannelPostMediaGroupFlow: Flow<EditChannelPostMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
val chosenInlineResultFlow: Flow<ChosenInlineResultUpdate> = allUpdatesFlow.filterIsInstance()
val inlineQueryFlow: Flow<InlineQueryUpdate> = allUpdatesFlow.filterIsInstance()
val callbackQueryFlow: Flow<CallbackQueryUpdate> = allUpdatesFlow.filterIsInstance()
val shippingQueryFlow: Flow<ShippingQueryUpdate> = allUpdatesFlow.filterIsInstance()
val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate> = allUpdatesFlow.filterIsInstance()
val pollFlow: Flow<PollUpdate> = allUpdatesFlow.filterIsInstance()
val pollAnswerFlow: Flow<PollAnswerUpdate> = allUpdatesFlow.filterIsInstance()
val unknownUpdateTypeFlow: Flow<UnknownUpdate> = allUpdatesFlow.filterIsInstance()
2019-05-10 03:54:57 +00:00
}