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:
Fabian Schlenz 2016-10-26 21:20:46 +02:00
parent e32924fc00
commit 3d213e9780
2 changed files with 42 additions and 12 deletions

View File

@ -167,6 +167,7 @@ public class DownloadManager {
private void downloadMessages(List<Integer> ids) throws RpcErrorException, IOException {
prog.onMessageDownloadStart(ids.size());
boolean has_seen_flood_wait_message = false;
logger.debug("Entering download loop");
while (ids.size()>0) {
@ -179,7 +180,30 @@ public class DownloadManager {
logger.trace("vector.size(): {}", vector.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());
db.saveMessages(response.getMessages(), Kotlogram.API_LAYER);
db.saveChats(response.getChats());

View File

@ -47,21 +47,27 @@ public class Utils {
}
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;
int delay = e.getTagInteger();
System.out.println("");
System.out.println(
"Telegram complained about us (okay, me) making too many requests in too short time by\n" +
"sending us \"" + e.getTag() + "\" as an error. So we now have to wait a bit. Telegram\n" +
"asked us to wait for " + delay + " seconds.\n" +
"\n" +
"So I'm going to do just that for now. If you don't want to wait, you can quit by pressing\n" +
"Ctrl+C. You can restart me at any time and I will just continue to download your\n" +
"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.");
if(!silent) {
System.out.println("");
System.out.println(
"Telegram complained about us (okay, me) making too many requests in too short time by\n" +
"sending us \"" + e.getTag() + "\" as an error. So we now have to wait a bit. Telegram\n" +
"asked us to wait for " + delay + " seconds.\n" +
"\n" +
"So I'm going to do just that for now. If you don't want to wait, you can quit by pressing\n" +
"Ctrl+C. You can restart me at any time and I will just continue to download your\n" +
"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) {}
System.out.println("");
}
static Version getNewestVersion() {