From 24fb3e21883d597c0d66720132a57f0d3ba262e2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 13 Apr 2019 16:06:58 +0800 Subject: [PATCH] clear of webhook on UpdatePoller start --- CHANGELOG.md | 2 ++ .../TelegramBotAPI/utils/extensions/UpdatesPoller.kt | 4 +++- .../TelegramBotAPI/utils/extensions/UpdatesPolling.kt | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 101e934954..b1e809a788 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,8 @@ of `]` in links titles * `kotlin serialization` version `0.10.0` -> `0.11.0` * `ktor` version `1.1.2` -> `1.1.3` * Added `DeleteWebhook` request +* All default `startGettingOfUpdates` (in fact - method `start` of `UpdatesPoller`) are suspend and +will try to delete webhook ## 0.11.0 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPoller.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPoller.kt index f0dd975b2a..7ead0ba33b 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPoller.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPoller.kt @@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.GetUpdates +import com.github.insanusmokrassar.TelegramBotAPI.requests.webhook.DeleteWebhook import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate @@ -72,7 +73,8 @@ class UpdatesPoller( pushMediaGroupUpdate() } - fun start(): Job { + suspend fun start(): Job { + executor.executeUnsafe(DeleteWebhook()) return pollerJob ?: scope.launch { while (isActive) { delay(requestsDelayMillis) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPolling.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPolling.kt index 257b1db839..8777aec2f5 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPolling.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPolling.kt @@ -9,7 +9,7 @@ import java.util.concurrent.Executors typealias UpdateReceiver = suspend (T) -> Unit -fun RequestsExecutor.startGettingOfUpdates( +suspend fun RequestsExecutor.startGettingOfUpdates( requestsDelayMillis: Long = 1000, scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), allowedUpdates: List? = null, @@ -18,7 +18,7 @@ fun RequestsExecutor.startGettingOfUpdates( return UpdatesPoller(this, requestsDelayMillis, scope, allowedUpdates, block).start() } -fun RequestsExecutor.startGettingOfUpdates( +suspend fun RequestsExecutor.startGettingOfUpdates( messageCallback: UpdateReceiver? = null, messageMediaGroupCallback: UpdateReceiver? = null, editedMessageCallback: UpdateReceiver? = null, @@ -58,7 +58,7 @@ fun RequestsExecutor.startGettingOfUpdates( ) } -fun RequestsExecutor.startGettingOfUpdates( +suspend fun RequestsExecutor.startGettingOfUpdates( messageCallback: UpdateReceiver? = null, mediaGroupCallback: UpdateReceiver? = null, editedMessageCallback: UpdateReceiver? = null,