added async delete, updateable msg
This commit is contained in:
parent
0e7e4408ac
commit
6bc04e719a
|
@ -22,6 +22,7 @@ public class MessageBuilder {
|
||||||
private Attachment attachmenttype = Attachment.none;
|
private Attachment attachmenttype = Attachment.none;
|
||||||
private String attachment = null;
|
private String attachment = null;
|
||||||
private String caption = null;
|
private String caption = null;
|
||||||
|
private int updates = 0;
|
||||||
|
|
||||||
public MessageBuilder setReciver(int id) {
|
public MessageBuilder setReciver(int id) {
|
||||||
reciver_id = id;
|
reciver_id = id;
|
||||||
|
@ -116,6 +117,11 @@ public class MessageBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MessageBuilder setUpdates(int oldmsgid) {
|
||||||
|
updates = oldmsgid;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public SendableMessage build() {
|
public SendableMessage build() {
|
||||||
if(reciver_id == 0) {
|
if(reciver_id == 0) {
|
||||||
throw new MissingException("Reciver");
|
throw new MissingException("Reciver");
|
||||||
|
@ -143,7 +149,11 @@ public class MessageBuilder {
|
||||||
attachment += "&" + attachmenttype.name().toLowerCase() + "=" + this.attachment;
|
attachment += "&" + attachmenttype.name().toLowerCase() + "=" + this.attachment;
|
||||||
cmd = "send" + attachmenttype.name();
|
cmd = "send" + attachmenttype.name();
|
||||||
} else {
|
} else {
|
||||||
cmd = "sendMessage";
|
if(updates > 0) {
|
||||||
|
cmd = "editMessageText";
|
||||||
|
optionals += "&message_id=" + updates;
|
||||||
|
} else
|
||||||
|
cmd = "sendMessage";
|
||||||
if(this.text != null) {
|
if(this.text != null) {
|
||||||
if(this.text.trim().isEmpty()) {
|
if(this.text.trim().isEmpty()) {
|
||||||
throw new MissingException("Text");
|
throw new MissingException("Text");
|
||||||
|
|
|
@ -96,16 +96,24 @@ public class TMessage extends JSONBased {
|
||||||
return forward_from;
|
return forward_from;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getMessageID() {
|
public int getMessageID() {
|
||||||
return message_id;
|
return message_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void delete(TelegramAPI api, int chatid, int msgid) {
|
public static void delete(TelegramAPI api, int chatid, int msgid) {
|
||||||
try {
|
delete(api, chatid, msgid, false);
|
||||||
api.request("deleteMessage", "chat_id=" + chatid + "&message_id=" + msgid);
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
public static void delete(TelegramAPI api, int chatid, int msgid, boolean async) {
|
||||||
|
String q = "chat_id=" + chatid + "&message_id=" + msgid;
|
||||||
|
if(async) {
|
||||||
|
api.requestAsync("deleteMessage", q);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
api.request("deleteMessage", q);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue