mirror of
https://github.com/fabianonline/telegram_backup.git
synced 2024-11-23 01:06:17 +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,9 +47,14 @@ 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();
|
||||||
|
if(!silent) {
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
System.out.println(
|
System.out.println(
|
||||||
"Telegram complained about us (okay, me) making too many requests in too short time by\n" +
|
"Telegram complained about us (okay, me) making too many requests in too short time by\n" +
|
||||||
@ -60,9 +65,10 @@ public class Utils {
|
|||||||
"Ctrl+C. You can restart me at any time and I will just continue to download your\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" +
|
"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.");
|
"the fact that Telegram won't talk to me until then.");
|
||||||
try { TimeUnit.SECONDS.sleep(delay + 1); } catch(InterruptedException e2) {}
|
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
}
|
}
|
||||||
|
try { TimeUnit.SECONDS.sleep(delay + 1); } catch(InterruptedException e2) {}
|
||||||
|
}
|
||||||
|
|
||||||
static Version getNewestVersion() {
|
static Version getNewestVersion() {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user