-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #738 from InsanusMokrassar/7.0.1
7.0.1
- Loading branch information
Showing
7 changed files
with
161 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/WithChat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package dev.inmo.tgbotapi.abstracts | ||
|
||
import dev.inmo.tgbotapi.types.chat.Chat | ||
|
||
/** | ||
* All inheritors of this interface have [chat] field and related to this [chat] | ||
*/ | ||
interface WithChat { | ||
val chat: Chat | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...pi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/FlowsSame.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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 <T : WithChat> Flow<T>.fromChat(chatId: ChatIdentifier): Flow<T> = filter { it.sameChat(chatId) } | ||
|
||
/** | ||
* Will pass only those [T] which have [sameChat] as [chatId] | ||
*/ | ||
@Suppress("NOTHING_TO_INLINE") | ||
inline fun <T : WithChat> Flow<T>.fromChat(chat: Chat): Flow<T> = fromChat(chat.id) | ||
|
||
/** | ||
* @return [Flow] with the [FromUser.user] field [User.id] the same as [userId] | ||
*/ | ||
@Suppress("NOTHING_TO_INLINE") | ||
inline fun <T : FromUser> Flow<T>.fromUser(userId: UserId): Flow<T> = 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 <T : FromUser> Flow<T>.fromUser(user: User): Flow<T> = fromUser(user.id) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters