From ab2a3ea23f08625477df8de194c39bdae8262c6d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 10 May 2019 11:54:57 +0800 Subject: [PATCH] add "FlowsUpdatesFilter" --- CHANGELOG.md | 1 + .../updateshandlers/FlowsUpdatesFilter.kt | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/FlowsUpdatesFilter.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index b79c03276e..56386fae3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ some default library * Replace `UpdatesFilter` and `UpdatesPoller` into another package * Replace `WebhookPrivateKeyConfig` +* Added `FlowsUpdatesFilter` ## 0.13.0 Telegram Polls diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/FlowsUpdatesFilter.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/FlowsUpdatesFilter.kt new file mode 100644 index 0000000000..0948630dca --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/FlowsUpdatesFilter.kt @@ -0,0 +1,60 @@ +package com.github.insanusmokrassar.TelegramBotAPI.updateshandlers + +import com.github.insanusmokrassar.TelegramBotAPI.types.update.* +import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.* +import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update +import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.UpdateReceiver +import kotlinx.coroutines.channels.BroadcastChannel +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.asFlow + +private fun BroadcastChannel.createUpdateReceiver(): UpdateReceiver = ::send + +class FlowsUpdatesFilter { + private val messageChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + private val messageMediaGroupChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + private val editedMessageChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + private val editedMessageMediaGroupChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + private val channelPostChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + private val channelPostMediaGroupChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + private val editedChannelPostChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + private val editedChannelPostMediaGroupChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + private val chosenInlineResultChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + private val inlineQueryChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + private val channelQueryChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + private val shippingQueryChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + private val preCheckoutQueryChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + + val filter = UpdatesFilter( + messageChannel.createUpdateReceiver(), + messageMediaGroupChannel.createUpdateReceiver(), + editedMessageChannel.createUpdateReceiver(), + editedMessageMediaGroupChannel.createUpdateReceiver(), + channelPostChannel.createUpdateReceiver(), + channelPostMediaGroupChannel.createUpdateReceiver(), + editedChannelPostChannel.createUpdateReceiver(), + editedChannelPostMediaGroupChannel.createUpdateReceiver(), + chosenInlineResultChannel.createUpdateReceiver(), + inlineQueryChannel.createUpdateReceiver(), + channelQueryChannel.createUpdateReceiver(), + shippingQueryChannel.createUpdateReceiver(), + preCheckoutQueryChannel.createUpdateReceiver() + ) + + val asUpdateReceiver: UpdateReceiver = filter.asUpdateReceiver + + val messageChannelFlow: Flow = messageChannel.asFlow() + val messageMediaGroupChannelFlow: Flow = messageMediaGroupChannel.asFlow() + val editedMessageChannelFlow: Flow = editedMessageChannel.asFlow() + val editedMessageMediaGroupChannelFlow: Flow = editedMessageMediaGroupChannel.asFlow() + val channelPostChannelFlow: Flow = channelPostChannel.asFlow() + val channelPostMediaGroupChannelFlow: Flow = channelPostMediaGroupChannel.asFlow() + val editedChannelPostChannelFlow: Flow = editedChannelPostChannel.asFlow() + val editedChannelPostMediaGroupChannelFlow: Flow = editedChannelPostMediaGroupChannel.asFlow() + val chosenInlineResultChannelFlow: Flow = chosenInlineResultChannel.asFlow() + val inlineQueryChannelFlow: Flow = inlineQueryChannel.asFlow() + val channelQueryChannelFlow: Flow = channelQueryChannel.asFlow() + val shippingQueryChannelFlow: Flow = shippingQueryChannel.asFlow() + val preCheckoutQueryChannelFlow: Flow = preCheckoutQueryChannel.asFlow() +} \ No newline at end of file