From e856dc4754575bb146d8574c436c11f01e2074f2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 15 May 2020 18:17:55 +0600 Subject: [PATCH] add flowsUdatesFilter --- CHANGELOG.md | 1 + TelegramBotAPI-extensions-utils/README.md | 12 ++++++++- .../utils/updates/FlowsUpdatesFactory.kt | 25 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/FlowsUpdatesFactory.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 262cbf573b..4f3f641986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,7 @@ * Updates utils were added * New extensions `startListenWebhooks`, `setWebhookInfoAndStartListenWebhooks` and `includeWebhookHandlingInRoute` was added * New extension `CoroutineScope#updateHandlerWithMediaGroupsAdaptation` was added + * New extension `flowsUpdatesFilter` was added * `TelegramBotAPI-all`: * Project was created diff --git a/TelegramBotAPI-extensions-utils/README.md b/TelegramBotAPI-extensions-utils/README.md index c138af694b..8c9fa129ff 100644 --- a/TelegramBotAPI-extensions-utils/README.md +++ b/TelegramBotAPI-extensions-utils/README.md @@ -76,7 +76,17 @@ updates retrieving: * Long Polling Both of them you could use in your project using [TelegramBotAPI](../TelegramBotAPI/README.md), but here there are -several useful extensions for both of them: +several useful extensions for both of them. + +Anyway, in both of ways it will be useful to know that it is possible to create `UpdateReceiver` object using function +`flowsUpdatesFilter`: + +```kotlin +val internalChannelsSizes = 128 +flowsUpdatesFilter(internalChannelsSizes/* default is 64 */) { + /* ... */ +} +``` #### Long polling diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/FlowsUpdatesFactory.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/FlowsUpdatesFactory.kt new file mode 100644 index 0000000000..297706c5b7 --- /dev/null +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/FlowsUpdatesFactory.kt @@ -0,0 +1,25 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates + +import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.FlowsUpdatesFilter + +/** + * Non-suspendable function for easy-to-use creating of [FlowsUpdatesFilter] and applying the block to it + */ +fun flowsUpdatesFilter( + internalChannelsSizes: Int = 64, + block: FlowsUpdatesFilter.() -> Unit +): FlowsUpdatesFilter = FlowsUpdatesFilter(internalChannelsSizes).apply(block) + +/** + * Suspend variation for [flowsUpdatesFilter] function + * + * @see flowsUpdatesFilter + */ +suspend fun flowsUpdatesFilter( + internalChannelsSizes: Int = 64, + block: suspend FlowsUpdatesFilter.() -> Unit +): FlowsUpdatesFilter { + val filter = FlowsUpdatesFilter(internalChannelsSizes) + filter.block() + return filter +}