updateMarkup & lowinternet handleing
This commit is contained in:
parent
3e289beec5
commit
69cb78ce5c
|
@ -1,5 +1,6 @@
|
||||||
package de.mrbesen.telegram;
|
package de.mrbesen.telegram;
|
||||||
|
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ public class AsyncHandler implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
int failed = 0;
|
||||||
while(!tasks.isEmpty()) {
|
while(!tasks.isEmpty()) {
|
||||||
Task current;
|
Task current;
|
||||||
|
|
||||||
|
@ -55,6 +57,16 @@ public class AsyncHandler implements Runnable {
|
||||||
callb = callb.next;
|
callb = callb.next;
|
||||||
// throw new Exception("Callbacktype missmatch! Got " + obj.getClass().getSimpleName() + " Wanted: " + wanted.getSimpleName() );
|
// throw new Exception("Callbacktype missmatch! Got " + obj.getClass().getSimpleName() + " Wanted: " + wanted.getSimpleName() );
|
||||||
}
|
}
|
||||||
|
failed = 0;
|
||||||
|
} catch(UnknownHostException ex) {//host(api.telegram.org) is good -> bad inet
|
||||||
|
failed ++;
|
||||||
|
if(failed > 10)
|
||||||
|
try {
|
||||||
|
Thread.yield();
|
||||||
|
Thread.sleep(1000);//wait 1 second
|
||||||
|
} catch(InterruptedException ignored) {}
|
||||||
|
//reenque
|
||||||
|
enque(current);
|
||||||
} catch(Throwable t) {
|
} catch(Throwable t) {
|
||||||
if(current.exceptionhandl == null)
|
if(current.exceptionhandl == null)
|
||||||
throw t;
|
throw t;
|
||||||
|
|
|
@ -210,6 +210,22 @@ public class TelegramAPI implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateMarkup(int chatid, int msg_id, TReplyMarkup rm, boolean async) {
|
||||||
|
try {
|
||||||
|
if(rm == null) return;//nope
|
||||||
|
|
||||||
|
String q = "chat_id=" + chatid + "&message_id=" + msg_id + "&reply_markup=" + URLEncoder.encode(rm.toJSONString(), "UTF-8");
|
||||||
|
|
||||||
|
if(async) {
|
||||||
|
this.async.enque("editMessageReplyMarkup", q);
|
||||||
|
} else {
|
||||||
|
request("editMessageReplyMarkup", q);
|
||||||
|
}
|
||||||
|
} catch(IOException e) {
|
||||||
|
log.log("", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
run = false;
|
run = false;
|
||||||
thread.interrupt();
|
thread.interrupt();
|
||||||
|
|
Loading…
Reference in New Issue