From 7e26ff0849517c6bc730fd4dc02c6ef9c1995c6f Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Mon, 5 Sep 2016 06:47:01 +0200 Subject: [PATCH] Added support for accounts having more than 1 million messages. --- .../telegram_backup/DownloadManager.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java index ce01450..59a5827 100644 --- a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java +++ b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java @@ -116,6 +116,12 @@ public class DownloadManager { max_database_id = Math.max(max_database_id, max_message_id-limit); System.out.println("New top message id 'in database' is " + max_database_id); } + if (max_message_id - max_database_id > 1000000) { + System.out.println("Would have to load more than 1 million messages which is not supported by telegram. Capping the list."); + logger.debug("max_message_id={}, max_database_id={}, difference={}", max_message_id, max_database_id, max_message_id - max_database_id); + max_database_id = Math.max(0, max_message_id - 1000000); + logger.debug("new max_database_id: {}", max_database_id); + } if (max_database_id == max_message_id) { System.out.println("No new messages to download."); @@ -141,11 +147,16 @@ public class DownloadManager { if (limit != null) { System.out.println("You are missing messages in your database. But since you're using '--limit-messages', I won't download these now."); } else { - LinkedList ids = db.getMissingIDs(); - count_missing = ids.size(); - System.out.println("Downloading " + ids.size() + " messages that are missing in your database."); + LinkedList all_missing_ids = db.getMissingIDs(); + LinkedList downloadable_missing_ids = new LinkedList(); + for (Integer id : all_missing_ids) { + if (id > max_message_id - 1000000) downloadable_missing_ids.add(id); + } + count_missing = all_missing_ids.size(); + System.out.println("" + all_missing_ids.size() + " messages are missing in your Database."); + System.out.println("I can (and will) download " + downloadable_missing_ids.size() + " of them."); - downloadMessages(ids); + downloadMessages(downloadable_missing_ids); } }