From 3919359f79166400a8a431a7b123183ef08ebefd Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 3 Oct 2021 18:44:29 +0600 Subject: [PATCH] CommonGroupEvent -> PublicChatEvent --- CHANGELOG.md | 2 +- .../types/message/ChatEvents/DeleteChatPhoto.kt | 4 ++-- .../types/message/ChatEvents/LeftChatMember.kt | 4 ++-- .../types/message/ChatEvents/NewChatPhoto.kt | 4 ++-- .../types/message/ChatEvents/NewChatTitle.kt | 4 ++-- .../message/ChatEvents/ProximityAlertTriggered.kt | 4 ++-- .../message/ChatEvents/abstracts/CommonEvent.kt | 2 +- .../ChatEvents/abstracts/CommonGroupEvent.kt | 3 --- .../ChatEvents/abstracts/PublicChatEvent.kt | 3 +++ .../ChatEvents/abstracts/VoiceChatEvent.kt | 2 +- .../expectations/WaitEventAction.kt | 6 +++--- .../triggers_handling/EventTriggers.kt | 10 +++++----- .../inmo/tgbotapi/extensions/utils/ClassCasts.kt | 15 ++++++++++++--- 13 files changed, 36 insertions(+), 27 deletions(-) delete mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/CommonGroupEvent.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/PublicChatEvent.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 4781e0e399..848faa2b00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ * `RowBuilder` and `MatrixBuilder` now are open and available for extending * `MatrixBuilder#matrix` will return read-only new list instead of original internal `mutMatrix` * Introduced new type of events `SuccessfulPaymentEvent` instead of putting of payment inside of message - * New type of events union: `CommonGroupEvent` + * New type of events union: `PublicChatEvent` * `Utils`: * Two new dsl: * `inlineKeyboard` for creating `InlineKeyboardMarkup` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/DeleteChatPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/DeleteChatPhoto.kt index 88401cc144..5af2d1d718 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/DeleteChatPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/DeleteChatPhoto.kt @@ -1,5 +1,5 @@ package dev.inmo.tgbotapi.types.message.ChatEvents -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonGroupEvent +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent -class DeleteChatPhoto: CommonGroupEvent +class DeleteChatPhoto: PublicChatEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt index 682ff86a91..a8b3bf1668 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt @@ -1,8 +1,8 @@ package dev.inmo.tgbotapi.types.message.ChatEvents import dev.inmo.tgbotapi.types.User -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonGroupEvent +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent data class LeftChatMember( val user: User -) : CommonGroupEvent +) : PublicChatEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/NewChatPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/NewChatPhoto.kt index 34640e408c..9b89ff7702 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/NewChatPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/NewChatPhoto.kt @@ -1,8 +1,8 @@ package dev.inmo.tgbotapi.types.message.ChatEvents import dev.inmo.tgbotapi.types.files.Photo -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonGroupEvent +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent data class NewChatPhoto( val photo: Photo -): CommonGroupEvent +): PublicChatEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/NewChatTitle.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/NewChatTitle.kt index 6ed5a469f6..0fbf9001b6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/NewChatTitle.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/NewChatTitle.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.types.message.ChatEvents -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonGroupEvent +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent data class NewChatTitle( val title: String -): CommonGroupEvent +): PublicChatEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt index 25604f2238..326385a38a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.message.ChatEvents import dev.inmo.tgbotapi.types.Meters import dev.inmo.tgbotapi.types.User -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonGroupEvent +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent import kotlinx.serialization.Serializable /** @@ -14,4 +14,4 @@ data class ProximityAlertTriggered( val traveler: User, val watcher: User, val distance: Meters -) : CommonGroupEvent +) : PublicChatEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/CommonEvent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/CommonEvent.kt index 0228be76e6..d40884f22e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/CommonEvent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/CommonEvent.kt @@ -1,3 +1,3 @@ package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts -interface CommonEvent : CommonGroupEvent, PrivateEvent +interface CommonEvent : PublicChatEvent, PrivateEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/CommonGroupEvent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/CommonGroupEvent.kt deleted file mode 100644 index 6432af9b0e..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/CommonGroupEvent.kt +++ /dev/null @@ -1,3 +0,0 @@ -package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts - -interface CommonGroupEvent : ChannelEvent, GroupEvent, SupergroupEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/PublicChatEvent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/PublicChatEvent.kt new file mode 100644 index 0000000000..04aa21ffd0 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/PublicChatEvent.kt @@ -0,0 +1,3 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts + +interface PublicChatEvent : ChannelEvent, GroupEvent, SupergroupEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/VoiceChatEvent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/VoiceChatEvent.kt index 33cf8c7a99..f06f52d765 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/VoiceChatEvent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/VoiceChatEvent.kt @@ -1,3 +1,3 @@ package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts -interface VoiceChatEvent : CommonGroupEvent +interface VoiceChatEvent : PublicChatEvent diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt index 96b5de3c83..81672cc796 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt @@ -127,12 +127,12 @@ suspend fun BehaviourContext.waitMessageAutoDeleteTimerChangedEvents( ) = waitEvents(count, initRequest, errorFactory, filter, mapper) -suspend fun BehaviourContext.waitCommonGroupEvents( +suspend fun BehaviourContext.waitPublicChatEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: SimpleFilter>? = null, - mapper: EventMessageToEventMapper? = null + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null ) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitCommonEvents( initRequest: Request<*>? = null, diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt index 1ee51b3c6c..00d4f6e447 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt @@ -189,11 +189,11 @@ suspend fun BehaviourContext.onMessageAutoDeleteTimerChangedEvent( * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that * data */ -suspend fun BehaviourContext.onCommonGroupEvent( - initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, - markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, - scenarioReceiver: BehaviourContextAndTypeReceiver> +suspend fun BehaviourContext.onPublicChatEvent( + initialFilter: SimpleFilter>? = null, + subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, + scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index 61e18f89c6..ad0e69f1f3 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -3043,13 +3043,22 @@ inline fun ChatEvent.asChannelEvent(): ChannelEvent? = this as? ChannelEvent inline fun ChatEvent.requireChannelEvent(): ChannelEvent = this as ChannelEvent @PreviewFeature -inline fun ChatEvent.whenCommonEvent(block: (CommonGroupEvent) -> T) = asCommonEvent() ?.let(block) +inline fun ChatEvent.whenPublicChatEvent(block: (PublicChatEvent) -> T) = asPublicChatEvent() ?.let(block) @PreviewFeature -inline fun ChatEvent.asCommonEvent(): CommonGroupEvent? = this as? CommonGroupEvent +inline fun ChatEvent.asPublicChatEvent(): PublicChatEvent? = this as? PublicChatEvent @PreviewFeature -inline fun ChatEvent.requireCommonEvent(): CommonGroupEvent = this as CommonGroupEvent +inline fun ChatEvent.requirePublicChatEvent(): PublicChatEvent = this as PublicChatEvent + +@PreviewFeature +inline fun ChatEvent.whenCommonEvent(block: (CommonEvent) -> T) = asCommonEvent() ?.let(block) + +@PreviewFeature +inline fun ChatEvent.asCommonEvent(): CommonEvent? = this as? CommonEvent + +@PreviewFeature +inline fun ChatEvent.requireCommonEvent(): CommonEvent = this as CommonEvent @PreviewFeature inline fun ChatEvent.whenGroupEvent(block: (GroupEvent) -> T) = asGroupEvent() ?.let(block)