From d8f830c60f8ca78eaa4ec2ed812be85d3ed3508f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 22 Aug 2021 23:14:56 +0600 Subject: [PATCH] FlowsUpdatesFilter update --- CHANGELOG.md | 2 + .../updateshandlers/FlowsUpdatesFilter.kt | 91 +++++++++++++++---- .../utils/extensions/FlowsUpdatesFilter.kt | 4 +- .../utils/shortcuts/EventsShortcuts.kt | 8 +- .../utils/shortcuts/FlowsUpdatesFilter.kt | 20 ++-- 5 files changed, 91 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 996a6af1f9..994908e575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ * `Version`: * `Klock`: `2.3.1` -> `2.3.3` * `MicroUtils`: `0.5.19` -> `0.5.21` +* `Core`: + * All `FlowsUpdatesFilter` flows have been renamed and updated * `Utils`: * Extensions `allSentMessagesFlow` and `allSentMediaGroupsFlow` have been deprecated diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt index de735db1c4..a926a0c719 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt @@ -14,24 +14,79 @@ interface FlowsUpdatesFilter : UpdatesFilter { val allUpdatesFlow: Flow val allUpdatesWithoutMediaGroupsGroupingFlow: Flow + val messagesFlow: Flow + val messageMediaGroupsFlow: Flow + val editedMessagesFlow: Flow + val editedMessageMediaGroupsFlow: Flow + val channelPostsFlow: Flow + val channelPostMediaGroupsFlow: Flow + val editedChannelPostsFlow: Flow + val editedChannelPostMediaGroupsFlow: Flow + val chosenInlineResultsFlow: Flow + val inlineQueriesFlow: Flow + val callbackQueriesFlow: Flow + val shippingQueriesFlow: Flow + val preCheckoutQueriesFlow: Flow + val pollsFlow: Flow + val pollAnswersFlow: Flow + val chatMemberUpdatesFlow: Flow + val myChatMemberUpdatesFlow: Flow + val unknownUpdatesFlow: Flow + + @Deprecated("Renamed", ReplaceWith("messagesFlow")) val messageFlow: Flow + get() = messagesFlow + @Deprecated("Renamed", ReplaceWith("messageMediaGroupsFlow")) val messageMediaGroupFlow: Flow + get() = messageMediaGroupsFlow + @Deprecated("Renamed", ReplaceWith("editedMessagesFlow")) val editedMessageFlow: Flow + get() = editedMessagesFlow + @Deprecated("Renamed", ReplaceWith("editedMessageMediaGroupsFlow")) val editedMessageMediaGroupFlow: Flow + get() = editedMessageMediaGroupsFlow + @Deprecated("Renamed", ReplaceWith("channelPostsFlow")) val channelPostFlow: Flow + get() = channelPostsFlow + @Deprecated("Renamed", ReplaceWith("channelPostMediaGroupsFlow")) val channelPostMediaGroupFlow: Flow + get() = channelPostMediaGroupsFlow + @Deprecated("Renamed", ReplaceWith("editedChannelPostsFlow")) val editedChannelPostFlow: Flow + get() = editedChannelPostsFlow + @Deprecated("Renamed", ReplaceWith("editedChannelPostMediaGroupsFlow")) val editedChannelPostMediaGroupFlow: Flow + get() = editedChannelPostMediaGroupsFlow + @Deprecated("Renamed", ReplaceWith("chosenInlineResultsFlow")) val chosenInlineResultFlow: Flow + get() = chosenInlineResultsFlow + @Deprecated("Renamed", ReplaceWith("inlineQueriesFlow")) val inlineQueryFlow: Flow + get() = inlineQueriesFlow + @Deprecated("Renamed", ReplaceWith("callbackQueriesFlow")) val callbackQueryFlow: Flow + get() = callbackQueriesFlow + @Deprecated("Renamed", ReplaceWith("shippingQueriesFlow")) val shippingQueryFlow: Flow + get() = shippingQueriesFlow + @Deprecated("Renamed", ReplaceWith("preCheckoutQueriesFlow")) val preCheckoutQueryFlow: Flow + get() = preCheckoutQueriesFlow + @Deprecated("Renamed", ReplaceWith("pollsFlow")) val pollFlow: Flow + get() = pollsFlow + @Deprecated("Renamed", ReplaceWith("pollAnswersFlow")) val pollAnswerFlow: Flow + get() = pollAnswersFlow + @Deprecated("Renamed", ReplaceWith("chatMemberUpdatesFlow")) val chatMemberUpdatedFlow: Flow + get() = chatMemberUpdatesFlow + @Deprecated("Renamed", ReplaceWith("myChatMemberUpdatesFlow")) val myChatMemberUpdatedFlow: Flow + get() = myChatMemberUpdatesFlow + @Deprecated("Renamed", ReplaceWith("unknownUpdatesFlow")) val unknownUpdateTypeFlow: Flow + get() = unknownUpdatesFlow } /** @@ -63,22 +118,22 @@ class DefaultFlowsUpdatesFilter( updatesSharedFlow.emit(it) } - override val messageFlow: Flow = allUpdatesFlow.filterIsInstance() - override val messageMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() - override val editedMessageFlow: Flow = allUpdatesFlow.filterIsInstance() - override val editedMessageMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() - override val channelPostFlow: Flow = allUpdatesFlow.filterIsInstance() - override val channelPostMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() - override val editedChannelPostFlow: Flow = allUpdatesFlow.filterIsInstance() - override val editedChannelPostMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() - override val chosenInlineResultFlow: Flow = allUpdatesFlow.filterIsInstance() - override val inlineQueryFlow: Flow = allUpdatesFlow.filterIsInstance() - override val callbackQueryFlow: Flow = allUpdatesFlow.filterIsInstance() - override val shippingQueryFlow: Flow = allUpdatesFlow.filterIsInstance() - override val preCheckoutQueryFlow: Flow = allUpdatesFlow.filterIsInstance() - override val pollFlow: Flow = allUpdatesFlow.filterIsInstance() - override val pollAnswerFlow: Flow = allUpdatesFlow.filterIsInstance() - override val chatMemberUpdatedFlow: Flow = allUpdatesFlow.filterIsInstance() - override val myChatMemberUpdatedFlow: Flow = allUpdatesFlow.filterIsInstance() - override val unknownUpdateTypeFlow: Flow = allUpdatesFlow.filterIsInstance() + override val messagesFlow: Flow = allUpdatesFlow.filterIsInstance() + override val messageMediaGroupsFlow: Flow = allUpdatesFlow.filterIsInstance() + override val editedMessagesFlow: Flow = allUpdatesFlow.filterIsInstance() + override val editedMessageMediaGroupsFlow: Flow = allUpdatesFlow.filterIsInstance() + override val channelPostsFlow: Flow = allUpdatesFlow.filterIsInstance() + override val channelPostMediaGroupsFlow: Flow = allUpdatesFlow.filterIsInstance() + override val editedChannelPostsFlow: Flow = allUpdatesFlow.filterIsInstance() + override val editedChannelPostMediaGroupsFlow: Flow = allUpdatesFlow.filterIsInstance() + override val chosenInlineResultsFlow: Flow = allUpdatesFlow.filterIsInstance() + override val inlineQueriesFlow: Flow = allUpdatesFlow.filterIsInstance() + override val callbackQueriesFlow: Flow = allUpdatesFlow.filterIsInstance() + override val shippingQueriesFlow: Flow = allUpdatesFlow.filterIsInstance() + override val preCheckoutQueriesFlow: Flow = allUpdatesFlow.filterIsInstance() + override val pollsFlow: Flow = allUpdatesFlow.filterIsInstance() + override val pollAnswersFlow: Flow = allUpdatesFlow.filterIsInstance() + override val chatMemberUpdatesFlow: Flow = allUpdatesFlow.filterIsInstance() + override val myChatMemberUpdatesFlow: Flow = allUpdatesFlow.filterIsInstance() + override val unknownUpdatesFlow: Flow = allUpdatesFlow.filterIsInstance() } diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/FlowsUpdatesFilter.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/FlowsUpdatesFilter.kt index df0464b6ce..168c4ca798 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/FlowsUpdatesFilter.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/FlowsUpdatesFilter.kt @@ -6,14 +6,14 @@ import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.merge -@Deprecated("Will be removed soon", ReplaceWith("messageFlow + channelPostFlow")) +@Deprecated("Will be removed soon", ReplaceWith("messagesFlow + channelPostsFlow")) val FlowsUpdatesFilter.allSentMessagesFlow: Flow get() = merge( messagesFlow, channelPostsFlow ) -@Deprecated("Will be removed soon", ReplaceWith("messageMediaGroupFlow + channelPostMediaGroupFlow")) +@Deprecated("Will be removed soon", ReplaceWith("messageMediaGroupsFlow + channelPostMediaGroupsFlow")) val FlowsUpdatesFilter.allSentMediaGroupsFlow: Flow get() = merge( messageMediaGroupsFlow, diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/EventsShortcuts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/EventsShortcuts.kt index 54df4bdd03..e51288d803 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/EventsShortcuts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/EventsShortcuts.kt @@ -14,21 +14,21 @@ import kotlinx.coroutines.flow.mapNotNull @RiskFeature("Use with caution") inline fun FlowsUpdatesFilter.events(): Flow> { - return channelPostFlow.mapNotNull { it.data as? ChatEventMessage<*> } + messageFlow.mapNotNull { it.data as? ChatEventMessage<*> } + return channelPostsFlow.mapNotNull { it.data as? ChatEventMessage<*> } + messagesFlow.mapNotNull { it.data as? ChatEventMessage<*> } } @RiskFeature("Use with caution") -inline fun FlowsUpdatesFilter.channelEvents(): Flow> = channelPostFlow.mapNotNull { +inline fun FlowsUpdatesFilter.channelEvents(): Flow> = channelPostsFlow.mapNotNull { it.data as? ChannelEventMessage<*> } @RiskFeature("Use with caution") -inline fun FlowsUpdatesFilter.groupEvents(): Flow> = messageFlow.mapNotNull { +inline fun FlowsUpdatesFilter.groupEvents(): Flow> = messagesFlow.mapNotNull { it.data as? GroupEventMessage<*> } @RiskFeature("Use with caution") -inline fun FlowsUpdatesFilter.supergroupEvents(): Flow> = messageFlow.mapNotNull { +inline fun FlowsUpdatesFilter.supergroupEvents(): Flow> = messagesFlow.mapNotNull { it.data as? SupergroupEventMessage<*> } diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/FlowsUpdatesFilter.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/FlowsUpdatesFilter.kt index 05b2fc0233..8964dd1ad3 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/FlowsUpdatesFilter.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/FlowsUpdatesFilter.kt @@ -47,8 +47,8 @@ inline fun Flow.filterMedi /** * @param scopeToIncludeChannels This parameter is required when you want to include [textMessages] for channels too. - * In this case will be created new channel which will aggregate messages from [FlowsUpdatesFilter.messageFlow] and - * [FlowsUpdatesFilter.channelPostFlow]. In case it is null will be used [Flow]s mapping + * In this case will be created new channel which will aggregate messages from [FlowsUpdatesFilter.messagesFlow] and + * [FlowsUpdatesFilter.channelPostsFlow]. In case it is null will be used [Flow]s mapping */ @Suppress("UNCHECKED_CAST") @RiskFeature(lowLevelRiskFeatureMessage) @@ -58,16 +58,16 @@ inline fun FlowsUpdatesFilter.filterContentMessages( return (scopeToIncludeChannels ?.let { scope -> aggregateFlows( scope, - messageFlow, - channelPostFlow + messagesFlow, + channelPostsFlow ) - } ?: messageFlow).filterContentMessages() + } ?: messagesFlow).filterContentMessages() } /** * @param scopeToIncludeChannels This parameter is required when you want to include [SentMediaGroupUpdate] for channels - * too. In this case will be created new channel which will aggregate messages from [FlowsUpdatesFilter.messageFlow] and - * [FlowsUpdatesFilter.channelPostFlow]. In case it is null will be used [Flow]s mapping + * too. In this case will be created new channel which will aggregate messages from [FlowsUpdatesFilter.messagesFlow] and + * [FlowsUpdatesFilter.channelPostsFlow]. In case it is null will be used [Flow]s mapping */ @Suppress("UNCHECKED_CAST") @RiskFeature(lowLevelRiskFeatureMessage) @@ -77,10 +77,10 @@ inline fun FlowsUpdatesFilter.filterMediaGroupMes return (scopeToIncludeChannels ?.let { scope -> aggregateFlows( scope, - messageMediaGroupFlow, - channelPostMediaGroupFlow + messageMediaGroupsFlow, + channelPostMediaGroupsFlow ) - } ?: messageMediaGroupFlow).filterMediaGroupMessages() + } ?: messageMediaGroupsFlow).filterMediaGroupMessages() } fun FlowsUpdatesFilter.sentMessages(