Skip to content

Commit 8fb8529

Browse files
committed
Add label field to ImageMap.
This closes #440. (thank you for reporting it)
1 parent 66a89ad commit 8fb8529

File tree

3 files changed

+72
-26
lines changed

3 files changed

+72
-26
lines changed

line-bot-model/src/main/java/com/linecorp/bot/model/message/imagemap/MessageImagemapAction.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,30 @@
1616

1717
package com.linecorp.bot.model.message.imagemap;
1818

19-
import com.fasterxml.jackson.annotation.JsonProperty;
2019
import com.fasterxml.jackson.annotation.JsonTypeName;
20+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
21+
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
2122

23+
import lombok.AccessLevel;
24+
import lombok.AllArgsConstructor;
25+
import lombok.Builder;
2226
import lombok.Value;
2327

2428
/**
2529
* MessageImagemapAction - When a region is tapped, the message specified in message is sent.
2630
*/
27-
@Value
2831
@JsonTypeName("message")
32+
@Value
33+
@Builder(toBuilder = true)
34+
@AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@Deprecated))
35+
// TODO: Remove next release. Use builder() instead.
36+
@JsonDeserialize(builder = MessageImagemapAction.MessageImagemapActionBuilder.class)
2937
public class MessageImagemapAction implements ImagemapAction {
38+
@JsonPOJOBuilder(withPrefix = "")
39+
public static class MessageImagemapActionBuilder {
40+
// Providing builder instead of public constructor. Class body is filled by lombok.
41+
}
42+
3043
/**
3144
* Message to send.
3245
*/
@@ -37,9 +50,17 @@ public class MessageImagemapAction implements ImagemapAction {
3750
*/
3851
ImagemapArea area;
3952

40-
public MessageImagemapAction(@JsonProperty("text") String text,
41-
@JsonProperty("area") ImagemapArea area) {
53+
String label;
54+
55+
/**
56+
* MessageImagemapAction constructor.
57+
*
58+
* @deprecated Use builder method instead. This construct will remove in next major release.
59+
*/
60+
@Deprecated
61+
public MessageImagemapAction(String text, ImagemapArea area) {
4262
this.text = text;
4363
this.area = area;
64+
this.label = null;
4465
}
4566
}

line-bot-model/src/main/java/com/linecorp/bot/model/message/imagemap/URIImagemapAction.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,30 @@
1616

1717
package com.linecorp.bot.model.message.imagemap;
1818

19-
import com.fasterxml.jackson.annotation.JsonProperty;
2019
import com.fasterxml.jackson.annotation.JsonTypeName;
20+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
21+
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
2122

23+
import lombok.AccessLevel;
24+
import lombok.AllArgsConstructor;
25+
import lombok.Builder;
2226
import lombok.Value;
2327

2428
/**
2529
* URLImagemapAction - When a region is tapped, the user is redirected to the URI specified.
2630
*/
27-
@Value
2831
@JsonTypeName("uri")
32+
@Value
33+
@Builder(toBuilder = true)
34+
@AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@Deprecated))
35+
// TODO: Remove next release. Use builder() instead.
36+
@JsonDeserialize(builder = URIImagemapAction.URIImagemapActionBuilder.class)
2937
public class URIImagemapAction implements ImagemapAction {
38+
@JsonPOJOBuilder(withPrefix = "")
39+
public static class URIImagemapActionBuilder {
40+
// Providing builder instead of public constructor. Class body is filled by lombok.
41+
}
42+
3043
/**
3144
* Webpage URL.
3245
*/
@@ -37,9 +50,17 @@ public class URIImagemapAction implements ImagemapAction {
3750
*/
3851
ImagemapArea area;
3952

40-
public URIImagemapAction(@JsonProperty("linkUri") String linkUri,
41-
@JsonProperty("area") ImagemapArea area) {
53+
String label;
54+
55+
/**
56+
* URIImagemapAction constructor.
57+
*
58+
* @deprecated Use builder method instead. This construct will remove in next major release.
59+
*/
60+
@Deprecated
61+
public URIImagemapAction(String linkUri, ImagemapArea area) {
4262
this.linkUri = linkUri;
4363
this.area = area;
64+
this.label = null;
4465
}
4566
}

sample-spring-boot-kitchensink/src/main/java/com/example/bot/spring/KitchenSinkController.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.util.concurrent.ExecutionException;
3434
import java.util.function.Consumer;
3535
import java.util.stream.Collectors;
36-
import java.util.stream.Stream;
3736

3837
import org.springframework.beans.factory.annotation.Autowired;
3938
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
@@ -492,18 +491,22 @@ private void handleTextContent(String replyToken, Event event, TextMessageConten
492491
.altText("This is alt text")
493492
.baseSize(new ImagemapBaseSize(1040, 1040))
494493
.actions(Arrays.asList(
495-
new URIImagemapAction(
496-
"https://store.line.me/family/manga/en",
497-
new ImagemapArea(0, 0, 520, 520)),
498-
new URIImagemapAction(
499-
"https://store.line.me/family/music/en",
500-
new ImagemapArea(520, 0, 520, 520)),
501-
new URIImagemapAction(
502-
"https://store.line.me/family/play/en",
503-
new ImagemapArea(0, 520, 520, 520)),
504-
new MessageImagemapAction(
505-
"URANAI!",
506-
new ImagemapArea(520, 520, 520, 520))
494+
URIImagemapAction.builder()
495+
.linkUri("https://store.line.me/family/manga/en")
496+
.area(new ImagemapArea(0, 0, 520, 520))
497+
.build(),
498+
URIImagemapAction.builder()
499+
.linkUri("https://store.line.me/family/music/en")
500+
.area(new ImagemapArea(520, 0, 520, 520))
501+
.build(),
502+
URIImagemapAction.builder()
503+
.linkUri("https://store.line.me/family/play/en")
504+
.area(new ImagemapArea(0, 520, 520, 520))
505+
.build(),
506+
MessageImagemapAction.builder()
507+
.text("URANAI!")
508+
.area(new ImagemapArea(520, 520, 520, 520))
509+
.build()
507510
))
508511
.build());
509512
break;
@@ -527,11 +530,12 @@ private void handleTextContent(String replyToken, Event event, TextMessageConten
527530
)
528531
.build()
529532
)
530-
.actions(Stream.of(
531-
new MessageImagemapAction(
532-
"NIXIE CLOCK",
533-
new ImagemapArea(260, 600, 450, 86)
534-
)).collect(Collectors.toList()))
533+
.actions(singletonList(
534+
MessageImagemapAction.builder()
535+
.text("NIXIE CLOCK")
536+
.area(new ImagemapArea(260, 600, 450, 86))
537+
.build()
538+
))
535539
.build());
536540
break;
537541
case "flex":

0 commit comments

Comments
 (0)