mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 00:57:13 +00:00
more "same" flow filters were added
This commit is contained in:
parent
741d808db2
commit
941a25b116
@ -1,7 +1,11 @@
|
||||
package dev.inmo.tgbotapi.extensions.utils.extensions
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.FromUser
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.transform
|
||||
|
||||
/**
|
||||
* @return true in case if [this] message is placed in the same chat that [other]
|
||||
@ -33,3 +37,15 @@ inline fun Message.sameTopic(other: Message) = sameChat(other) && threadIdOrNull
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun Message.sameThread(other: Message) = sameChat(other) && threadIdOrNull == other.threadIdOrNull
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun <T : Message> Flow<T>.filterSameChat(chatId: IdChatIdentifier): Flow<T> =
|
||||
transform { value ->
|
||||
if (value.chat.id.chatId == chatId.chatId) return@transform emit(value)
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun <T : FromUser> Flow<T>.filterSameUser(userId: IdChatIdentifier): Flow<T> =
|
||||
transform { value ->
|
||||
if (value.from.id.chatId == userId.chatId) return@transform emit(value)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user