1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-25 19:48:43 +00:00

sentMessages extension for FlowsUpdatesFilter

This commit is contained in:
InsanusMokrassar 2020-08-13 15:28:10 +06:00
parent 790959ea49
commit d2228e274c
3 changed files with 22 additions and 0 deletions

View File

@ -56,6 +56,8 @@
* Extensions for `FlowUpdatesFilter` were added:
* `FlowsUpdatesFilter#allSentMessagesFlow` (combination of `messageFlow` and `channelPostFlow`)
* `FlowsUpdatesFilter#allSentMediaGroupsFlow` (combination of `messageMediaGroupFlow` and `channelPostMediaGroupFlow`)
* `FlowsUpdatesFilter#sentMessages`
* `FlowsUpdatesFilter#sentMessagesWithMediaGroups`
* `FlowsUpdatesFilter#photoMessagesWithMediaGroups`
* `FlowsUpdatesFilter#imageMessagesWithMediaGroups`
* `FlowsUpdatesFilter#videoMessagesWithMediaGroups`

View File

@ -29,3 +29,11 @@ fun <T> Flow<Iterable<T>>.flatMap(): Flow<T> = flow {
}
}
}
fun <T, R> Flow<T>.flatMap(mapper: (T) -> Iterable<R>): Flow<R> = flow {
collect {
mapper(it).forEach {
emit(it)
}
}
}

View File

@ -75,6 +75,18 @@ inline fun <reified T: MediaGroupContent> FlowsUpdatesFilter.filterMediaGroupMes
} ?: messageMediaGroupFlow).filterMediaGroupMessages()
}
fun FlowsUpdatesFilter.sentMessages(
scopeToIncludeChannels: CoroutineScope? = null
): Flow<ContentMessage<MessageContent>> = filterContentMessages(scopeToIncludeChannels)
fun FlowsUpdatesFilter.sentMessagesWithMediaGroups(
scopeToIncludeChannels: CoroutineScope? = null
): Flow<ContentMessage<MessageContent>> = merge(
sentMessages(scopeToIncludeChannels),
mediaGroupMessages(scopeToIncludeChannels).flatMap {
it.mapNotNull { it as? ContentMessage<MessageContent> }
}
)
fun Flow<BaseSentMessageUpdate>.animationMessages() = filterContentMessages<AnimationContent>()
fun FlowsUpdatesFilter.animationMessages(
scopeToIncludeChannels: CoroutineScope? = null