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 String attachment = null;
|
||||
private String caption = null;
|
||||
private int updates = 0;
|
||||
|
||||
public MessageBuilder setReciver(int id) {
|
||||
reciver_id = id;
|
||||
|
@ -116,6 +117,11 @@ public class MessageBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public MessageBuilder setUpdates(int oldmsgid) {
|
||||
updates = oldmsgid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendableMessage build() {
|
||||
if(reciver_id == 0) {
|
||||
throw new MissingException("Reciver");
|
||||
|
@ -143,7 +149,11 @@ public class MessageBuilder {
|
|||
attachment += "&" + attachmenttype.name().toLowerCase() + "=" + this.attachment;
|
||||
cmd = "send" + attachmenttype.name();
|
||||
} else {
|
||||
cmd = "sendMessage";
|
||||
if(updates > 0) {
|
||||
cmd = "editMessageText";
|
||||
optionals += "&message_id=" + updates;
|
||||
} else
|
||||
cmd = "sendMessage";
|
||||
if(this.text != null) {
|
||||
if(this.text.trim().isEmpty()) {
|
||||
throw new MissingException("Text");
|
||||
|
|
|
@ -96,16 +96,24 @@ public class TMessage extends JSONBased {
|
|||
return forward_from;
|
||||
}
|
||||
|
||||
|
||||
public int getMessageID() {
|
||||
return message_id;
|
||||
}
|
||||
|
||||
public static void delete(TelegramAPI api, int chatid, int msgid) {
|
||||
try {
|
||||
api.request("deleteMessage", "chat_id=" + chatid + "&message_id=" + msgid);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
delete(api, chatid, msgid, false);
|
||||
}
|
||||
|
||||
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