From e8c28b4e72f532e0482a6aef4378c4feccf9890a Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Thu, 12 Apr 2018 05:56:30 +0200 Subject: [PATCH] `--limit-messages` now also affects channels and supergroups. --- .../fabianonline/telegram_backup/DownloadManager.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt index f452c2f..2545443 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt @@ -140,19 +140,22 @@ class DownloadManager(val client: TelegramClient, val prog: DownloadProgressInte if (settings.download_channels) { println("Checking channels...") - for (channel in chats.channels) { if (channel.download) downloadMessagesFromChannel(channel) } + for (channel in chats.channels) { if (channel.download) downloadMessagesFromChannel(channel, limit) } } if (settings.download_supergroups) { println("Checking supergroups...") - for (supergroup in chats.supergroups) { if (supergroup.download) downloadMessagesFromChannel(supergroup) } + for (supergroup in chats.supergroups) { if (supergroup.download) downloadMessagesFromChannel(supergroup, limit) } } } - private fun downloadMessagesFromChannel(channel: Channel) { + private fun downloadMessagesFromChannel(channel: Channel, limit: Int?) { val obj = channel.obj - val max_known_id = db.getTopMessageIDForChannel(channel.id) + var max_known_id = db.getTopMessageIDForChannel(channel.id) if (obj.getTopMessage() > max_known_id) { + if (limit != null) { + max_known_id = Math.max(max_known_id, obj.getTopMessage() - limit) + } val ids = makeIdList(max_known_id + 1, obj.getTopMessage()) var channel_name = channel.title