From 19f473cfe5ec5290c6e7c5d45c4a2e6e88c36bec Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Mon, 9 May 2016 02:01:31 +0200 Subject: [PATCH] Compute message entities content during Message deserialization --- .../org/telegram/telegrambots/api/objects/Message.java | 4 ++++ .../telegrambots/api/objects/MessageEntity.java | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Message.java b/src/main/java/org/telegram/telegrambots/api/objects/Message.java index 6f68a03a..05414b84 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Message.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Message.java @@ -219,6 +219,10 @@ public class Message implements IBotApiObject { if (jsonObject.has(MIGRATEFROMCHAT_FIELD)) { this.migrateFromChatId = jsonObject.getLong(MIGRATEFROMCHAT_FIELD); } + + if (hasText() && entities != null) { + entities.forEach(x -> x.computeText(text)); + } } public Integer getMessageId() { diff --git a/src/main/java/org/telegram/telegrambots/api/objects/MessageEntity.java b/src/main/java/org/telegram/telegrambots/api/objects/MessageEntity.java index b436f51f..14a9bccc 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/MessageEntity.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/MessageEntity.java @@ -45,6 +45,8 @@ public class MessageEntity implements IBotApiObject { @JsonProperty(URL_FIELD) private String url; ///< Optional. For “text_link” only, url that will be opened after user taps on the text + private String text; ///< Text present in the entity. Computed from offset and length + public MessageEntity() { super(); } @@ -75,6 +77,14 @@ public class MessageEntity implements IBotApiObject { return url; } + public String getText() { + return text; + } + + protected void computeText(String message) { + text = message.substring(offset, offset + length); + } + @Override public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { gen.writeStartObject();