Добавил идентификатор сообщения в ButtonClickAttachment

This commit is contained in:
Struchkov Mark 2022-12-21 19:28:55 +03:00
parent 57694fd40a
commit ff2d302db5
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
2 changed files with 19 additions and 2 deletions

View File

@ -20,7 +20,7 @@ public class CallbackQueryConvert {
final Mail mail = new Mail(); final Mail mail = new Mail();
mail.setCreateDate(LocalDateTime.now()); mail.setCreateDate(LocalDateTime.now());
mail.setText(callbackData); mail.setText(callbackData);
mail.addAttachment(convertToButtonClick(callbackData)); mail.addAttachment(convertToButtonClick(callbackData, callbackQuery.getMessage().getMessageId()));
final Long chatId = callbackQuery.getMessage().getChatId(); final Long chatId = callbackQuery.getMessage().getChatId();
mail.setPersonId(chatId != null ? chatId.toString() : null); mail.setPersonId(chatId != null ? chatId.toString() : null);
@ -31,9 +31,10 @@ public class CallbackQueryConvert {
return mail; return mail;
} }
private static ButtonClickAttachment convertToButtonClick(String callbackData) { private static ButtonClickAttachment convertToButtonClick(String callbackData, Integer messageId) {
final ButtonClickAttachment buttonClickAttachment = new ButtonClickAttachment(); final ButtonClickAttachment buttonClickAttachment = new ButtonClickAttachment();
buttonClickAttachment.setRawCallBackData(callbackData); buttonClickAttachment.setRawCallBackData(callbackData);
buttonClickAttachment.setMessageId(messageId);
if (callbackData.charAt(0) == '[' && callbackData.charAt(callbackData.length() - 1) == ']') { if (callbackData.charAt(0) == '[' && callbackData.charAt(callbackData.length() - 1) == ']') {
final String[] args = callbackData.substring(1, callbackData.length() - 1).split(";"); final String[] args = callbackData.substring(1, callbackData.length() - 1).split(";");
for (String arg : args) { for (String arg : args) {

View File

@ -12,6 +12,10 @@ import static dev.struchkov.haiti.utils.Inspector.isNotNull;
public class ButtonClickAttachment extends Attachment { public class ButtonClickAttachment extends Attachment {
/**
* Идентификатор сообщения, под которым пользователь нажал кнопку.
*/
private Integer messageId;
private String rawCallBackData; private String rawCallBackData;
private final Map<String, Arg> args = new HashMap<>(); private final Map<String, Arg> args = new HashMap<>();
@ -42,6 +46,18 @@ public class ButtonClickAttachment extends Attachment {
return args.values(); return args.values();
} }
public Integer getMessageId() {
return messageId;
}
public void setMessageId(Integer messageId) {
this.messageId = messageId;
}
public Map<String, Arg> getArgs() {
return args;
}
@Override @Override
public String getType() { public String getType() {
return TelegramAttachmentType.BUTTON_CLICK.name(); return TelegramAttachmentType.BUTTON_CLICK.name();