1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

FlowsUpdatesFilter update

This commit is contained in:
InsanusMokrassar 2021-08-22 23:14:56 +06:00
parent 226b8dee21
commit d8f830c60f
5 changed files with 91 additions and 34 deletions

View File

@ -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

View File

@ -14,24 +14,79 @@ interface FlowsUpdatesFilter : UpdatesFilter {
val allUpdatesFlow: Flow<Update>
val allUpdatesWithoutMediaGroupsGroupingFlow: Flow<Update>
val messagesFlow: Flow<MessageUpdate>
val messageMediaGroupsFlow: Flow<MessageMediaGroupUpdate>
val editedMessagesFlow: Flow<EditMessageUpdate>
val editedMessageMediaGroupsFlow: Flow<EditMessageMediaGroupUpdate>
val channelPostsFlow: Flow<ChannelPostUpdate>
val channelPostMediaGroupsFlow: Flow<ChannelPostMediaGroupUpdate>
val editedChannelPostsFlow: Flow<EditChannelPostUpdate>
val editedChannelPostMediaGroupsFlow: Flow<EditChannelPostMediaGroupUpdate>
val chosenInlineResultsFlow: Flow<ChosenInlineResultUpdate>
val inlineQueriesFlow: Flow<InlineQueryUpdate>
val callbackQueriesFlow: Flow<CallbackQueryUpdate>
val shippingQueriesFlow: Flow<ShippingQueryUpdate>
val preCheckoutQueriesFlow: Flow<PreCheckoutQueryUpdate>
val pollsFlow: Flow<PollUpdate>
val pollAnswersFlow: Flow<PollAnswerUpdate>
val chatMemberUpdatesFlow: Flow<CommonChatMemberUpdatedUpdate>
val myChatMemberUpdatesFlow: Flow<MyChatMemberUpdatedUpdate>
val unknownUpdatesFlow: Flow<UnknownUpdate>
@Deprecated("Renamed", ReplaceWith("messagesFlow"))
val messageFlow: Flow<MessageUpdate>
get() = messagesFlow
@Deprecated("Renamed", ReplaceWith("messageMediaGroupsFlow"))
val messageMediaGroupFlow: Flow<MessageMediaGroupUpdate>
get() = messageMediaGroupsFlow
@Deprecated("Renamed", ReplaceWith("editedMessagesFlow"))
val editedMessageFlow: Flow<EditMessageUpdate>
get() = editedMessagesFlow
@Deprecated("Renamed", ReplaceWith("editedMessageMediaGroupsFlow"))
val editedMessageMediaGroupFlow: Flow<EditMessageMediaGroupUpdate>
get() = editedMessageMediaGroupsFlow
@Deprecated("Renamed", ReplaceWith("channelPostsFlow"))
val channelPostFlow: Flow<ChannelPostUpdate>
get() = channelPostsFlow
@Deprecated("Renamed", ReplaceWith("channelPostMediaGroupsFlow"))
val channelPostMediaGroupFlow: Flow<ChannelPostMediaGroupUpdate>
get() = channelPostMediaGroupsFlow
@Deprecated("Renamed", ReplaceWith("editedChannelPostsFlow"))
val editedChannelPostFlow: Flow<EditChannelPostUpdate>
get() = editedChannelPostsFlow
@Deprecated("Renamed", ReplaceWith("editedChannelPostMediaGroupsFlow"))
val editedChannelPostMediaGroupFlow: Flow<EditChannelPostMediaGroupUpdate>
get() = editedChannelPostMediaGroupsFlow
@Deprecated("Renamed", ReplaceWith("chosenInlineResultsFlow"))
val chosenInlineResultFlow: Flow<ChosenInlineResultUpdate>
get() = chosenInlineResultsFlow
@Deprecated("Renamed", ReplaceWith("inlineQueriesFlow"))
val inlineQueryFlow: Flow<InlineQueryUpdate>
get() = inlineQueriesFlow
@Deprecated("Renamed", ReplaceWith("callbackQueriesFlow"))
val callbackQueryFlow: Flow<CallbackQueryUpdate>
get() = callbackQueriesFlow
@Deprecated("Renamed", ReplaceWith("shippingQueriesFlow"))
val shippingQueryFlow: Flow<ShippingQueryUpdate>
get() = shippingQueriesFlow
@Deprecated("Renamed", ReplaceWith("preCheckoutQueriesFlow"))
val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate>
get() = preCheckoutQueriesFlow
@Deprecated("Renamed", ReplaceWith("pollsFlow"))
val pollFlow: Flow<PollUpdate>
get() = pollsFlow
@Deprecated("Renamed", ReplaceWith("pollAnswersFlow"))
val pollAnswerFlow: Flow<PollAnswerUpdate>
get() = pollAnswersFlow
@Deprecated("Renamed", ReplaceWith("chatMemberUpdatesFlow"))
val chatMemberUpdatedFlow: Flow<CommonChatMemberUpdatedUpdate>
get() = chatMemberUpdatesFlow
@Deprecated("Renamed", ReplaceWith("myChatMemberUpdatesFlow"))
val myChatMemberUpdatedFlow: Flow<MyChatMemberUpdatedUpdate>
get() = myChatMemberUpdatesFlow
@Deprecated("Renamed", ReplaceWith("unknownUpdatesFlow"))
val unknownUpdateTypeFlow: Flow<UnknownUpdate>
get() = unknownUpdatesFlow
}
/**
@ -63,22 +118,22 @@ class DefaultFlowsUpdatesFilter(
updatesSharedFlow.emit(it)
}
override val messageFlow: Flow<MessageUpdate> = allUpdatesFlow.filterIsInstance()
override val messageMediaGroupFlow: Flow<MessageMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
override val editedMessageFlow: Flow<EditMessageUpdate> = allUpdatesFlow.filterIsInstance()
override val editedMessageMediaGroupFlow: Flow<EditMessageMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
override val channelPostFlow: Flow<ChannelPostUpdate> = allUpdatesFlow.filterIsInstance()
override val channelPostMediaGroupFlow: Flow<ChannelPostMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
override val editedChannelPostFlow: Flow<EditChannelPostUpdate> = allUpdatesFlow.filterIsInstance()
override val editedChannelPostMediaGroupFlow: Flow<EditChannelPostMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
override val chosenInlineResultFlow: Flow<ChosenInlineResultUpdate> = allUpdatesFlow.filterIsInstance()
override val inlineQueryFlow: Flow<InlineQueryUpdate> = allUpdatesFlow.filterIsInstance()
override val callbackQueryFlow: Flow<CallbackQueryUpdate> = allUpdatesFlow.filterIsInstance()
override val shippingQueryFlow: Flow<ShippingQueryUpdate> = allUpdatesFlow.filterIsInstance()
override val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate> = allUpdatesFlow.filterIsInstance()
override val pollFlow: Flow<PollUpdate> = allUpdatesFlow.filterIsInstance()
override val pollAnswerFlow: Flow<PollAnswerUpdate> = allUpdatesFlow.filterIsInstance()
override val chatMemberUpdatedFlow: Flow<CommonChatMemberUpdatedUpdate> = allUpdatesFlow.filterIsInstance()
override val myChatMemberUpdatedFlow: Flow<MyChatMemberUpdatedUpdate> = allUpdatesFlow.filterIsInstance()
override val unknownUpdateTypeFlow: Flow<UnknownUpdate> = allUpdatesFlow.filterIsInstance()
override val messagesFlow: Flow<MessageUpdate> = allUpdatesFlow.filterIsInstance()
override val messageMediaGroupsFlow: Flow<MessageMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
override val editedMessagesFlow: Flow<EditMessageUpdate> = allUpdatesFlow.filterIsInstance()
override val editedMessageMediaGroupsFlow: Flow<EditMessageMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
override val channelPostsFlow: Flow<ChannelPostUpdate> = allUpdatesFlow.filterIsInstance()
override val channelPostMediaGroupsFlow: Flow<ChannelPostMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
override val editedChannelPostsFlow: Flow<EditChannelPostUpdate> = allUpdatesFlow.filterIsInstance()
override val editedChannelPostMediaGroupsFlow: Flow<EditChannelPostMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
override val chosenInlineResultsFlow: Flow<ChosenInlineResultUpdate> = allUpdatesFlow.filterIsInstance()
override val inlineQueriesFlow: Flow<InlineQueryUpdate> = allUpdatesFlow.filterIsInstance()
override val callbackQueriesFlow: Flow<CallbackQueryUpdate> = allUpdatesFlow.filterIsInstance()
override val shippingQueriesFlow: Flow<ShippingQueryUpdate> = allUpdatesFlow.filterIsInstance()
override val preCheckoutQueriesFlow: Flow<PreCheckoutQueryUpdate> = allUpdatesFlow.filterIsInstance()
override val pollsFlow: Flow<PollUpdate> = allUpdatesFlow.filterIsInstance()
override val pollAnswersFlow: Flow<PollAnswerUpdate> = allUpdatesFlow.filterIsInstance()
override val chatMemberUpdatesFlow: Flow<CommonChatMemberUpdatedUpdate> = allUpdatesFlow.filterIsInstance()
override val myChatMemberUpdatesFlow: Flow<MyChatMemberUpdatedUpdate> = allUpdatesFlow.filterIsInstance()
override val unknownUpdatesFlow: Flow<UnknownUpdate> = allUpdatesFlow.filterIsInstance()
}

View File

@ -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<BaseSentMessageUpdate>
get() = merge(
messagesFlow,
channelPostsFlow
)
@Deprecated("Will be removed soon", ReplaceWith("messageMediaGroupFlow + channelPostMediaGroupFlow"))
@Deprecated("Will be removed soon", ReplaceWith("messageMediaGroupsFlow + channelPostMediaGroupsFlow"))
val FlowsUpdatesFilter.allSentMediaGroupsFlow: Flow<SentMediaGroupUpdate>
get() = merge(
messageMediaGroupsFlow,

View File

@ -14,21 +14,21 @@ import kotlinx.coroutines.flow.mapNotNull
@RiskFeature("Use with caution")
inline fun FlowsUpdatesFilter.events(): Flow<ChatEventMessage<*>> {
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<ChannelEventMessage<*>> = channelPostFlow.mapNotNull {
inline fun FlowsUpdatesFilter.channelEvents(): Flow<ChannelEventMessage<*>> = channelPostsFlow.mapNotNull {
it.data as? ChannelEventMessage<*>
}
@RiskFeature("Use with caution")
inline fun FlowsUpdatesFilter.groupEvents(): Flow<GroupEventMessage<*>> = messageFlow.mapNotNull {
inline fun FlowsUpdatesFilter.groupEvents(): Flow<GroupEventMessage<*>> = messagesFlow.mapNotNull {
it.data as? GroupEventMessage<*>
}
@RiskFeature("Use with caution")
inline fun FlowsUpdatesFilter.supergroupEvents(): Flow<SupergroupEventMessage<*>> = messageFlow.mapNotNull {
inline fun FlowsUpdatesFilter.supergroupEvents(): Flow<SupergroupEventMessage<*>> = messagesFlow.mapNotNull {
it.data as? SupergroupEventMessage<*>
}

View File

@ -47,8 +47,8 @@ inline fun <reified T : MediaGroupContent> Flow<SentMediaGroupUpdate>.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 <reified T: MessageContent> 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 <reified T: MediaGroupContent> FlowsUpdatesFilter.filterMediaGroupMes
return (scopeToIncludeChannels ?.let { scope ->
aggregateFlows(
scope,
messageMediaGroupFlow,
channelPostMediaGroupFlow
messageMediaGroupsFlow,
channelPostMediaGroupsFlow
)
} ?: messageMediaGroupFlow).filterMediaGroupMessages()
} ?: messageMediaGroupsFlow).filterMediaGroupMessages()
}
fun FlowsUpdatesFilter.sentMessages(