From 22eac5414c673be7fab483abec03ad76366e8fd0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 21 Dec 2021 19:13:49 +0600 Subject: [PATCH 1/6] start 0.37.4 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94877dd28a..20f099d3f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.37.4 + ## 0.37.3 Hotfix of 0.37.3 * `Core`: diff --git a/gradle.properties b/gradle.properties index 4fd64ecc26..f2fa486dae 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.8.7 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.37.3 +library_version=0.37.4 github_release_plugin_version=2.2.12 From aa1e7eea1dcba10879042bb8b3907bdde7a959b0 Mon Sep 17 00:00:00 2001 From: madhead Date: Mon, 20 Dec 2021 23:10:41 +0100 Subject: [PATCH 2/6] Support for "migrated to supergroup" events --- CHANGELOG.md | 3 ++ .../message/ChatEvents/GroupChatCreated.kt | 4 +- .../ChatEvents/MigratedToSupergroup.kt | 11 ++++ .../ChatEvents/SupergroupChatCreated.kt | 4 +- .../inmo/tgbotapi/types/message/RawMessage.kt | 7 ++- .../ChatEvents/MigratedToSupergroupTest.kt | 52 +++++++++++++++++++ .../tgbotapi/extensions/utils/ClassCasts.kt | 9 ++++ 7 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroup.kt create mode 100644 tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroupTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 20f099d3f0..bb83257bb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # TelegramBotAPI changelog ## 0.37.4 +* `Core`: + * New `SupergroupEvent` subtype: `MigratedToSupergroup`. This event is sent when a group is converted to a supergroup while bot is in the group. + * Helper extenstion functions on `ChatEvent` to cast it to `MigratedToSupergroup`. ## 0.37.3 Hotfix of 0.37.3 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/GroupChatCreated.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/GroupChatCreated.kt index edecacfd6a..4ac21f5771 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/GroupChatCreated.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/GroupChatCreated.kt @@ -1,8 +1,8 @@ package dev.inmo.tgbotapi.types.message.ChatEvents -import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent class GroupChatCreated( - val migratedTo: ChatIdentifier? + val migratedTo: ChatId? ): GroupEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroup.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroup.kt new file mode 100644 index 0000000000..8b230e75ce --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroup.kt @@ -0,0 +1,11 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents + +import dev.inmo.tgbotapi.types.ChatId +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent + +/** + * This event is sent when a group is converted to a supergroup. + */ +class MigratedToSupergroup( + val migratedFrom: ChatId +): SupergroupEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/SupergroupChatCreated.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/SupergroupChatCreated.kt index 5ea4ef8247..31830380cb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/SupergroupChatCreated.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/SupergroupChatCreated.kt @@ -1,8 +1,8 @@ package dev.inmo.tgbotapi.types.message.ChatEvents -import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent class SupergroupChatCreated( - val migratedFrom: ChatIdentifier? + val migratedFrom: ChatId? ): SupergroupEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 343afb1f75..c0fcc5334b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -75,8 +75,8 @@ internal data class RawMessage( private val group_chat_created: Boolean = false, private val supergroup_chat_created: Boolean = false, private val channel_chat_created: Boolean = false, - private val migrate_to_chat_id: ChatIdentifier? = null, - private val migrate_from_chat_id: ChatIdentifier? = null, + private val migrate_to_chat_id: ChatId? = null, + private val migrate_from_chat_id: ChatId? = null, private val pinned_message: RawMessage? = null, private val invoice: Invoice? = null, private val dice: Dice? = null, @@ -194,6 +194,9 @@ internal data class RawMessage( supergroup_chat_created -> SupergroupChatCreated( migrate_from_chat_id ) + migrate_from_chat_id != null -> MigratedToSupergroup( + migrate_from_chat_id + ) channel_chat_created -> ChannelChatCreated() pinned_message != null -> PinnedMessage(pinned_message.asMessage) proximity_alert_triggered != null -> proximity_alert_triggered diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroupTest.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroupTest.kt new file mode 100644 index 0000000000..91b4f3dafe --- /dev/null +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroupTest.kt @@ -0,0 +1,52 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents + +import dev.inmo.tgbotapi.TestsJsonFormat +import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate +import dev.inmo.tgbotapi.extensions.utils.asMigratedToSupergroup +import dev.inmo.tgbotapi.extensions.utils.asSupergroupChatCreated +import dev.inmo.tgbotapi.extensions.utils.asSupergroupEventMessage +import dev.inmo.tgbotapi.types.ChatId +import dev.inmo.tgbotapi.types.update.abstracts.UpdateDeserializationStrategy +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertIs +import kotlin.test.fail + + +class MigratedToSupergroupTest { + @Test + fun `MigratedToSupergroup event should be parsed`() { + val payload = """ + { + "update_id": 42, + "message": { + "message_id": 1, + "from": { + "id": 1087968824, + "is_bot": true, + "first_name": "Group", + "username": "GroupAnonymousBot" + }, + "sender_chat": { + "id": 42, + "title": "MigratedToSupergroupTest", + "type": "supergroup" + }, + "chat": { + "id": 42, + "title": "MigratedToSupergroupTest", + "type": "supergroup" + }, + "date": 1639955462, + "migrate_from_chat_id": 57005 + } + } + """.trimIndent() + val update = TestsJsonFormat.decodeFromString(UpdateDeserializationStrategy, payload) + val message = update.asMessageUpdate() ?: fail("update should be of MessageUpdate subtype") + val data = message.data.asSupergroupEventMessage() ?: fail("message should be of SupergroupEventMessage subtype") + val event = data.chatEvent.asMigratedToSupergroup() ?: fail("event should be of SupergroupChatCreated subtype") + + assertEquals(ChatId(57005), event.migratedFrom) + } +} \ No newline at end of file diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index 52af1c45fe..a0e7317dc1 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -3081,6 +3081,15 @@ inline fun ChatEvent.asSupergroupChatCreated(): SupergroupChatCreated? = this as @PreviewFeature inline fun ChatEvent.requireSupergroupChatCreated(): SupergroupChatCreated = this as SupergroupChatCreated +@PreviewFeature +inline fun ChatEvent.whenMigratedToSupergroup(block: (MigratedToSupergroup) -> T) = asMigratedToSupergroup() ?.let(block) + +@PreviewFeature +inline fun ChatEvent.asMigratedToSupergroup(): MigratedToSupergroup? = this as? MigratedToSupergroup + +@PreviewFeature +inline fun ChatEvent.requireMigratedToSupergroup(): MigratedToSupergroup = this as MigratedToSupergroup + @PreviewFeature inline fun ChatEvent.whenChannelEvent(block: (ChannelEvent) -> T) = asChannelEvent() ?.let(block) From faf669c0350e8c2ddf7b012c3ee020a93051ff1b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 27 Dec 2021 22:48:21 +0600 Subject: [PATCH 3/6] Update gradle.properties --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index f2fa486dae..8607184b4e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.4.8 uuid_version=0.3.1 ktor_version=1.6.5 -micro_utils_version=0.8.7 +micro_utils_version=0.8.9 javax_activation_version=1.1.1 From 8675833b9985a6e8a35e2a7bf37dbf64a0984a35 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 27 Dec 2021 22:50:09 +0600 Subject: [PATCH 4/6] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb83257bb7..263c6a32b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # TelegramBotAPI changelog ## 0.37.4 + +* `Common`: + * `Version`: + * `MicroUtils`: `0.8.7` -> `0.8.9` * `Core`: * New `SupergroupEvent` subtype: `MigratedToSupergroup`. This event is sent when a group is converted to a supergroup while bot is in the group. * Helper extenstion functions on `ChatEvent` to cast it to `MigratedToSupergroup`. From dca5bb40e3004c95490ecf34ce2e092acd7b832b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 27 Dec 2021 23:06:51 +0600 Subject: [PATCH 5/6] Update MigratedToSupergroup.kt --- .../tgbotapi/types/message/ChatEvents/MigratedToSupergroup.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroup.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroup.kt index 8b230e75ce..276deeb0e1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroup.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroup.kt @@ -6,6 +6,6 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent /** * This event is sent when a group is converted to a supergroup. */ -class MigratedToSupergroup( +data class MigratedToSupergroup( val migratedFrom: ChatId ): SupergroupEvent From 6f1f94299b001c0c9be901d07cb9c815a975458e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 30 Dec 2021 12:30:09 +0600 Subject: [PATCH 6/6] fix of build --- .../types/message/ChatEvents/MigratedToSupergroupTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroupTest.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroupTest.kt index 91b4f3dafe..4c243155a3 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroupTest.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroupTest.kt @@ -15,7 +15,7 @@ import kotlin.test.fail class MigratedToSupergroupTest { @Test - fun `MigratedToSupergroup event should be parsed`() { + fun MigratedToSupergroupEventShouldBeParsed() { val payload = """ { "update_id": 42, @@ -49,4 +49,4 @@ class MigratedToSupergroupTest { assertEquals(ChatId(57005), event.migratedFrom) } -} \ No newline at end of file +}