Compute message entities content during Message deserialization

This commit is contained in:
Rubenlagus 2016-05-09 02:01:31 +02:00
parent 199152e9bf
commit 19f473cfe5
2 changed files with 14 additions and 0 deletions

View File

@ -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() {

View File

@ -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();