package dev.inmo.tgbotapi.extensions.utils.extensions import dev.inmo.tgbotapi.abstracts.FromUser import dev.inmo.tgbotapi.abstracts.WithChat import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.chat.User import dev.inmo.tgbotapi.types.message.abstracts.Message import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.transform /** * Will pass only those [T] which have [sameChat] as [chatId] */ @Suppress("NOTHING_TO_INLINE") inline fun Flow.fromChat(chatId: ChatIdentifier): Flow = filter { it.sameChat(chatId) } /** * Will pass only those [T] which have [sameChat] as [chatId] */ @Suppress("NOTHING_TO_INLINE") inline fun Flow.fromChat(chat: Chat): Flow = fromChat(chat.id) /** * @return [Flow] with the [FromUser.user] field [User.id] the same as [userId] */ @Suppress("NOTHING_TO_INLINE") inline fun Flow.fromUser(userId: UserId): Flow = filter { it.user.id == userId } /** * @return [Flow] with the [FromUser.user] field [User.id] the same as [user] [User.id] */ @Suppress("NOTHING_TO_INLINE") inline fun Flow.fromUser(user: User): Flow = fromUser(user.id)