diff --git a/CHANGELOG.md b/CHANGELOG.md index 05fd2c1807..5f6ffa0f19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ * `TextContent#entities` has been deprecated * `GroupEventMessage` now overrides `chatEvent` with type `GroupEvent` * `SupergroupEventMessage` now overrides `chatEvent` with type `SupergroupEvent` + * Any `ChatEventMessage` now have generic type of its `chatEvent` (just like messages) +* `Utils`: + * A lot of extensions for `Flow` has been added ## 0.30.3 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 4f3493d206..24f83fcae4 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 @@ -1,35 +1,22 @@ +@file:Suppress("NOTHING_TO_INLINE", "unused") + package dev.inmo.tgbotapi.extensions.utils.shortcuts -import dev.inmo.tgbotapi.extensions.utils.aggregateFlows import dev.inmo.tgbotapi.types.message.ChannelEventMessage import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.abstracts.* -import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import dev.inmo.tgbotapi.utils.RiskFeature -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.* -/** - * @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 - */ -@Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE") @RiskFeature("Use with caution") -inline fun FlowsUpdatesFilter.filterChannelEvents(): Flow> = channelPostFlow.mapNotNull { +inline fun FlowsUpdatesFilter.channelEvents(): Flow> = channelPostFlow.mapNotNull { it.data as? ChannelEventMessage<*> } -/** - * @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 - */ -@Suppress("UNCHECKED_CAST") @RiskFeature("Use with caution") -inline fun > FlowsUpdatesFilter.filterGroupEvents(): Flow = messageFlow.mapNotNull { +inline fun > FlowsUpdatesFilter.groupEvents(): Flow = messageFlow.mapNotNull { it.data as? T }