1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-05 16:19:26 +00:00

add ChatEventsConversations and refill README of telegramboapi-extensions-utils

This commit is contained in:
2020-05-10 16:25:42 +06:00
parent 565a724b9c
commit 34eb6eb4bf
3 changed files with 76 additions and 4 deletions

View File

@@ -0,0 +1,21 @@
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils
import com.github.insanusmokrassar.TelegramBotAPI.types.message.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.mapNotNull
import kotlin.reflect.KClass
fun <T : ChatEventMessage> Flow<ChatEventMessage>.divideBySource(contentType: KClass<T>) = mapNotNull {
if (contentType.isInstance(it)) {
@Suppress("UNCHECKED_CAST")
it as T
} else {
null
}
}
fun Flow<ChatEventMessage>.channelEvents() = divideBySource(ChannelEventMessage::class)
fun Flow<ChatEventMessage>.groupEvents() = divideBySource(GroupEventMessage::class)
fun Flow<ChatEventMessage>.supergroupEvents() = divideBySource(SupergroupEventMessage::class)