From 99574c6e6e5268fa240acc2c3a8f0d11e78f5b9f Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Fri, 1 Dec 2017 21:17:13 +0100 Subject: [PATCH] Split --with-channels-and-supergroups into seperate switches --with-channels and --with-supergroups. --- .../CommandLineController.java | 4 ++-- .../telegram_backup/CommandLineOptions.java | 10 +++++++--- .../telegram_backup/DownloadManager.java | 20 +++++++++++++++++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java b/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java index 5a2291b..6e92ac1 100644 --- a/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java +++ b/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java @@ -298,8 +298,8 @@ public class CommandLineController { System.out.println(" -d, --daemon Keep running and automatically save new messages."); System.out.println(" --anonymize (Try to) Remove all sensitive information from output. Useful for requesting support."); System.out.println(" --stats Print some usage statistics."); - System.out.println(" --with-channels-and-supergroups"); - System.out.println(" Backup channels and supergroups as well."); + System.out.println(" --with-channels Backup channels as well."); + System.out.println(" --with-supergroups Backup supergroups as well."); } private void list_accounts() { diff --git a/src/main/java/de/fabianonline/telegram_backup/CommandLineOptions.java b/src/main/java/de/fabianonline/telegram_backup/CommandLineOptions.java index d206343..f355a7d 100644 --- a/src/main/java/de/fabianonline/telegram_backup/CommandLineOptions.java +++ b/src/main/java/de/fabianonline/telegram_backup/CommandLineOptions.java @@ -30,7 +30,8 @@ class CommandLineOptions { public static boolean cmd_no_media = false; public static boolean cmd_anonymize = false; public static boolean cmd_stats = false; - public static boolean cmd_channels_and_supergroups = false; + public static boolean cmd_channels = false; + public static boolean cmd_supergroups = false; public static String val_account = null; public static Integer val_limit_messages = null; @@ -118,8 +119,11 @@ class CommandLineOptions { case "--stats": cmd_stats = true; break; - case "--with-channels-and-supergroups": - cmd_channels_and_supergroups = true; break; + case "--with-channels": + cmd_channels = true; break; + + case "--with-supergroups": + cmd_supergroups = true; break; default: throw new RuntimeException("Unknown command " + arg); diff --git a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java index c433418..eb1f624 100644 --- a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java +++ b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java @@ -169,11 +169,14 @@ public class DownloadManager { } */ - if (CommandLineOptions.cmd_channels_and_supergroups) { - System.out.println("Processing channels and supergroups..."); + if (CommandLineOptions.cmd_channels || CommandLineOptions.cmd_supergroups) { + System.out.println("Processing channels and/or supergroups..."); + System.out.println("Please note that only channels/supergroups in the last 100 active chats are processed."); HashMap channel_access_hashes = new HashMap(); HashMap channel_names = new HashMap(); + LinkedList channels = new LinkedList(); + LinkedList supergroups = new LinkedList(); // TODO Add chat title (and other stuff?) to the database for (TLAbsChat c : dialogs.getChats()) { @@ -181,6 +184,11 @@ public class DownloadManager { TLChannel ch = (TLChannel)c; channel_access_hashes.put(c.getId(), ch.getAccessHash()); channel_names.put(c.getId(), ch.getTitle()); + if (ch.getMegagroup()) { + supergroups.add(c.getId()); + } else { + channels.add(c.getId()); + } // Channel: TLChannel // Supergroup: getMegagroup()==true } @@ -191,6 +199,14 @@ public class DownloadManager { for (TLDialog d : dialogs.getDialogs()) { if (d.getPeer() instanceof TLPeerChannel) { int channel_id = ((TLPeerChannel)d.getPeer()).getChannelId(); + + // If this is a channel and we don't want to download channels OR + // it is a supergroups and we don't want to download supergroups, then + if ((channels.contains(channel_id) && !CommandLineOptions.cmd_channels) || + (supergroups.contains(channel_id) && !CommandLineOptions.cmd_supergroups)) { + // Skip this chat. + continue; + } int max_known_id = db.getTopMessageIDForChannel(channel_id); if (d.getTopMessage() > max_known_id) { List ids = makeIdList(max_known_id+1, d.getTopMessage());