mirror of
				https://github.com/InsanusMokrassar/TelegramBotAPI.git
				synced 2025-10-26 09:40:09 +00:00 
			
		
		
		
	Merge pull request #737 from Tolsi/more-same-flow-filters
more "same" flow filters were added
This commit is contained in:
		| @@ -1,7 +1,11 @@ | |||||||
| package dev.inmo.tgbotapi.extensions.utils.extensions | 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.types.message.abstracts.Message | ||||||
| import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull | 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] |  * @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") | @Suppress("NOTHING_TO_INLINE") | ||||||
| inline fun Message.sameThread(other: Message) = sameChat(other) && threadIdOrNull == other.threadIdOrNull | 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) | ||||||
|  |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user