diff --git a/src/main/lombok/com/restfb/types/webhook/AbstractMentionAddValue.java b/src/main/lombok/com/restfb/types/webhook/AbstractMentionAddValue.java new file mode 100644 index 000000000..89b5cc4c8 --- /dev/null +++ b/src/main/lombok/com/restfb/types/webhook/AbstractMentionAddValue.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2010-2021 Mark Allen, Norbert Bartels. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.restfb.types.webhook; + +import com.restfb.Facebook; +import com.restfb.types.webhook.base.BaseChangeValue; +import lombok.Getter; +import lombok.Setter; + +abstract public class AbstractMentionAddValue extends BaseChangeValue { + + @Getter + @Setter + @Facebook("post_id") + private String postId; + + @Deprecated + @Getter + @Setter + @Facebook("sender_id") + private String senderId; + + @Deprecated + @Getter + @Setter + @Facebook("sender_name") + private String senderName; +} diff --git a/src/main/lombok/com/restfb/types/webhook/ChangeValueFactory.java b/src/main/lombok/com/restfb/types/webhook/ChangeValueFactory.java index fbc8d4ee1..4b9d3c17f 100644 --- a/src/main/lombok/com/restfb/types/webhook/ChangeValueFactory.java +++ b/src/main/lombok/com/restfb/types/webhook/ChangeValueFactory.java @@ -151,6 +151,7 @@ enum ChangeValueEnumeration { FEED_LIKE_ADD(FeedLikeValue.class), // FEED_LIKE_REMOVE(FeedLikeValue.class), // MENTION_POST_ADD(MentionPostAddValue.class), // + MENTION_COMMENT_ADD(MentionCommentAddValue.class), // RATINGS_RATING_ADD(RatingsRatingValue.class), // RATINGS_RATING_EDIT(RatingsRatingValue.class), // RATINGS_RATING_REMOVE(RatingsRatingValue.class), // diff --git a/src/main/lombok/com/restfb/types/webhook/MentionCommentAddValue.java b/src/main/lombok/com/restfb/types/webhook/MentionCommentAddValue.java new file mode 100644 index 000000000..3aef402c3 --- /dev/null +++ b/src/main/lombok/com/restfb/types/webhook/MentionCommentAddValue.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010-2021 Mark Allen, Norbert Bartels. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.restfb.types.webhook; + +import com.restfb.Facebook; +import lombok.Getter; +import lombok.Setter; + +public class MentionCommentAddValue extends AbstractMentionAddValue { + + @Getter + @Setter + @Facebook("comment_id") + private String commentId; + +} diff --git a/src/main/lombok/com/restfb/types/webhook/MentionPostAddValue.java b/src/main/lombok/com/restfb/types/webhook/MentionPostAddValue.java index 17d834940..dda62d087 100644 --- a/src/main/lombok/com/restfb/types/webhook/MentionPostAddValue.java +++ b/src/main/lombok/com/restfb/types/webhook/MentionPostAddValue.java @@ -21,26 +21,6 @@ */ package com.restfb.types.webhook; -import com.restfb.Facebook; -import com.restfb.types.webhook.base.BaseChangeValue; +public class MentionPostAddValue extends AbstractMentionAddValue { -import lombok.Getter; -import lombok.Setter; - -public class MentionPostAddValue extends BaseChangeValue { - - @Getter - @Setter - @Facebook("post_id") - private String postId; - - @Getter - @Setter - @Facebook("sender_id") - private String senderId; - - @Getter - @Setter - @Facebook("sender_name") - private String senderName; } diff --git a/src/main/lombok/com/restfb/types/webhook/base/AbstractFeedPostValue.java b/src/main/lombok/com/restfb/types/webhook/base/AbstractFeedPostValue.java index 9dd837c07..1c269b105 100644 --- a/src/main/lombok/com/restfb/types/webhook/base/AbstractFeedPostValue.java +++ b/src/main/lombok/com/restfb/types/webhook/base/AbstractFeedPostValue.java @@ -33,10 +33,12 @@ abstract public class AbstractFeedPostValue extends BaseChangeValue { @Facebook("post_id") private String postId; + @Deprecated @Setter @Facebook("sender_id") private String senderId; + @Deprecated @Setter @Facebook("sender_name") private String senderName; diff --git a/src/test/java/com/restfb/types/WebhookTest.java b/src/test/java/com/restfb/types/WebhookTest.java index 050d8ff56..c75e6ef50 100644 --- a/src/test/java/com/restfb/types/WebhookTest.java +++ b/src/test/java/com/restfb/types/WebhookTest.java @@ -1250,6 +1250,31 @@ void mentionPostAdd() { assertEquals(ChangeValue.Verb.ADD, mentionPostAddValue.getVerb()); } + @Test + void mentionPostAdd_realData() { + WebhookObject webhookObject = openJson("mention-post-add-real"); + Change change = webhookObject.getEntryList().get(0).getChanges().get(0); + assertEquals(change.getValue().getClass(), MentionPostAddValue.class, "change value class"); + MentionPostAddValue mentionPostAddValue = (MentionPostAddValue) change.getValue(); + assertNotNull(mentionPostAddValue); + assertEquals("1234567890321_98722536423179", mentionPostAddValue.getPostId()); + assertEquals("post", mentionPostAddValue.getItem()); + assertEquals(ChangeValue.Verb.ADD, mentionPostAddValue.getVerb()); + } + + @Test + void mentionCommentAdd() { + WebhookObject webhookObject = openJson("mention-comment-add"); + Change change = webhookObject.getEntryList().get(0).getChanges().get(0); + assertEquals(change.getValue().getClass(), MentionCommentAddValue.class, "change value class"); + MentionCommentAddValue mentionCommentAddValue = (MentionCommentAddValue) change.getValue(); + assertNotNull(mentionCommentAddValue); + assertEquals("1234567890321_7363534231324", mentionCommentAddValue.getPostId()); + assertEquals("7363534231324_3754798971271444", mentionCommentAddValue.getCommentId()); + assertEquals("comment", mentionCommentAddValue.getItem()); + assertEquals(ChangeValue.Verb.ADD, mentionCommentAddValue.getVerb()); + } + @Test void feedTwoEntries() { WebhookObject webhookObject = openJson("feed-two-entries-25"); diff --git a/src/test/resources/json/webhooks/mention-comment-add.json b/src/test/resources/json/webhooks/mention-comment-add.json new file mode 100644 index 000000000..31c5754ae --- /dev/null +++ b/src/test/resources/json/webhooks/mention-comment-add.json @@ -0,0 +1,22 @@ +{ + "object": "page", + "entry": [ + { + "id": "1234567890321", + "time": 1614340868, + "changes": [ + { + "value": { + "message": "Just a test message", + "post_id": "1234567890321_7363534231324", + "comment_id": "7363534231324_3754798971271444", + "created_time": 1614340862, + "item": "comment", + "verb": "add" + }, + "field": "mention" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/test/resources/json/webhooks/mention-post-add-real.json b/src/test/resources/json/webhooks/mention-post-add-real.json new file mode 100644 index 000000000..0a65376ff --- /dev/null +++ b/src/test/resources/json/webhooks/mention-post-add-real.json @@ -0,0 +1,21 @@ +{ + "object": "page", + "entry": [ + { + "id": "1234567890321", + "time": 1614340567, + "changes": [ + { + "value": { + "message": "A test post message", + "post_id": "1234567890321_98722536423179", + "created_time": 1614340562, + "item": "post", + "verb": "add" + }, + "field": "mention" + } + ] + } + ] +} \ No newline at end of file