1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-12-25 14:25:35 +00:00

Split --with-channels-and-supergroups into seperate switches --with-channels and --with-supergroups.

This commit is contained in:
Fabian Schlenz 2017-12-01 21:17:13 +01:00
parent b8d9e2a1b6
commit 99574c6e6e
3 changed files with 27 additions and 7 deletions

View File

@ -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() {

View File

@ -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);

View File

@ -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<Integer, Long> channel_access_hashes = new HashMap<Integer, Long>();
HashMap<Integer, String> channel_names = new HashMap<Integer, String>();
LinkedList<Integer> channels = new LinkedList<Integer>();
LinkedList<Integer> supergroups = new LinkedList<Integer>();
// 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<Integer> ids = makeIdList(max_known_id+1, d.getTopMessage());