mirror of
https://github.com/fabianonline/telegram_backup.git
synced 2024-11-22 16:56:16 +00:00
obeyFloodWaitException() now also has a silent mode for repeated FLOOD_WAITs. Also, DownloadController now also checks if the amount of returned messages equals the number of requested messages.
This commit is contained in:
parent
e32924fc00
commit
3d213e9780
@ -167,6 +167,7 @@ public class DownloadManager {
|
|||||||
|
|
||||||
private void downloadMessages(List<Integer> ids) throws RpcErrorException, IOException {
|
private void downloadMessages(List<Integer> ids) throws RpcErrorException, IOException {
|
||||||
prog.onMessageDownloadStart(ids.size());
|
prog.onMessageDownloadStart(ids.size());
|
||||||
|
boolean has_seen_flood_wait_message = false;
|
||||||
|
|
||||||
logger.debug("Entering download loop");
|
logger.debug("Entering download loop");
|
||||||
while (ids.size()>0) {
|
while (ids.size()>0) {
|
||||||
@ -179,7 +180,30 @@ public class DownloadManager {
|
|||||||
logger.trace("vector.size(): {}", vector.size());
|
logger.trace("vector.size(): {}", vector.size());
|
||||||
logger.trace("ids.size(): {}", ids.size());
|
logger.trace("ids.size(): {}", ids.size());
|
||||||
|
|
||||||
TLAbsMessages response = client.messagesGetMessages(vector);
|
TLAbsMessages response;
|
||||||
|
int tries = 0;
|
||||||
|
while(true) {
|
||||||
|
logger.trace("Trying getMessages(), tries={}", tries);
|
||||||
|
if (tries>=5) {
|
||||||
|
CommandLineController.show_error("Couldn't getMessages after 5 tries. Quitting.");
|
||||||
|
}
|
||||||
|
tries++;
|
||||||
|
try {
|
||||||
|
response = client.messagesGetMessages(vector);
|
||||||
|
break;
|
||||||
|
} catch (RpcErrorException e) {
|
||||||
|
if (e.getCode()==420) { // FLOOD_WAIT
|
||||||
|
Utils.obeyFloodWaitException(e, has_seen_flood_wait_message);
|
||||||
|
has_seen_flood_wait_message = true;
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.trace("response.getMessages().size(): {}", response.getMessages().size());
|
||||||
|
if (response.getMessages().size() != vector.size()) {
|
||||||
|
CommandLineController.show_error("Requested " + vector.size() + " messages, but got " + response.getMessages().size() + ". That is unexpected. Quitting.");
|
||||||
|
}
|
||||||
prog.onMessageDownloaded(response.getMessages().size());
|
prog.onMessageDownloaded(response.getMessages().size());
|
||||||
db.saveMessages(response.getMessages(), Kotlogram.API_LAYER);
|
db.saveMessages(response.getMessages(), Kotlogram.API_LAYER);
|
||||||
db.saveChats(response.getChats());
|
db.saveChats(response.getChats());
|
||||||
|
@ -47,21 +47,27 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void obeyFloodWaitException(RpcErrorException e) throws RpcErrorException {
|
static void obeyFloodWaitException(RpcErrorException e) throws RpcErrorException {
|
||||||
|
obeyFloodWaitException(e, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void obeyFloodWaitException(RpcErrorException e, boolean silent) throws RpcErrorException {
|
||||||
if (e==null || e.getCode()!=420) return;
|
if (e==null || e.getCode()!=420) return;
|
||||||
|
|
||||||
int delay = e.getTagInteger();
|
int delay = e.getTagInteger();
|
||||||
System.out.println("");
|
if(!silent) {
|
||||||
System.out.println(
|
System.out.println("");
|
||||||
"Telegram complained about us (okay, me) making too many requests in too short time by\n" +
|
System.out.println(
|
||||||
"sending us \"" + e.getTag() + "\" as an error. So we now have to wait a bit. Telegram\n" +
|
"Telegram complained about us (okay, me) making too many requests in too short time by\n" +
|
||||||
"asked us to wait for " + delay + " seconds.\n" +
|
"sending us \"" + e.getTag() + "\" as an error. So we now have to wait a bit. Telegram\n" +
|
||||||
"\n" +
|
"asked us to wait for " + delay + " seconds.\n" +
|
||||||
"So I'm going to do just that for now. If you don't want to wait, you can quit by pressing\n" +
|
"\n" +
|
||||||
"Ctrl+C. You can restart me at any time and I will just continue to download your\n" +
|
"So I'm going to do just that for now. If you don't want to wait, you can quit by pressing\n" +
|
||||||
"messages and media. But be advised that just restarting me is not going to change\n" +
|
"Ctrl+C. You can restart me at any time and I will just continue to download your\n" +
|
||||||
"the fact that Telegram won't talk to me until then.");
|
"messages and media. But be advised that just restarting me is not going to change\n" +
|
||||||
|
"the fact that Telegram won't talk to me until then.");
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
try { TimeUnit.SECONDS.sleep(delay + 1); } catch(InterruptedException e2) {}
|
try { TimeUnit.SECONDS.sleep(delay + 1); } catch(InterruptedException e2) {}
|
||||||
System.out.println("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Version getNewestVersion() {
|
static Version getNewestVersion() {
|
||||||
|
Loading…
Reference in New Issue
Block a user