Skip to content

Commit

Permalink
Issue #741 - support webhook reaction on comments and replies
Browse files Browse the repository at this point in the history
  • Loading branch information
nbartels committed Jun 17, 2017
1 parent 44be643 commit c6c1d39
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 67 deletions.
35 changes: 34 additions & 1 deletion source/library/com/restfb/types/webhook/FeedReactionValue.java
Expand Up @@ -28,7 +28,7 @@
import lombok.Setter;

/**
* Change value describing a reaction to a post.
* Change value describing a reaction to a post/comment/reply.
*/
public class FeedReactionValue extends AbstractFeedPostValue {

Expand All @@ -42,4 +42,37 @@ public class FeedReactionValue extends AbstractFeedPostValue {
@Facebook("reaction_type")
private String reactionType;

@Getter
@Setter
@Facebook("comment_id")
private String commentId;

/**
* returns <code>true</code> if the reaction was made on a Post
*
* @return <code>true</code> if the reaction was made on a Post
*/
public boolean isPostReaction() {
return commentId == null;
}

/**
* returns <code>true</code> if the reaction was made on a Comment, <code>false</code> if the reaction was made on a
* post
*
* @return <code>true</code> if the reaction was made on a Comment
*/
public boolean isCommentReaction() {
return commentId != null;
}

/**
* returns <code>true</code> if the reaction was made on a Reply (comment of a comment),
*
* @return <code>true</code> if the reaction was made on a Reply
*/
public boolean isReplyReaction() {
return commentId != null && !getPostId().equals(parentId);
}

}
31 changes: 31 additions & 0 deletions source/test/java/com/restfb/types/WebhookTest.java
Expand Up @@ -236,6 +236,37 @@ public void feedReactionAdd() {
assertEquals("1234567890321_901097836652708", value.getParentId());
assertEquals("1234567890321", value.getSenderId());
assertEquals("love", value.getReactionType());
assertTrue(value.isPostReaction());
assertFalse(value.isCommentReaction());
assertFalse(value.isReplyReaction());
}

@Test
public void feedReactionCommentAdd() {
FeedReactionValue value =
openAndCheckFeedPostBasics("feed-reaction-add-comment", FeedReactionValue.class, ITEM_REACTION, ChangeValue.Verb.ADD);
assertEquals("1234567890321_98735342324352", value.getPostId());
assertEquals("1234567890321_98735342324352", value.getParentId());
assertEquals("1234567890321_1264545546974600", value.getCommentId());
assertEquals("1234567890321", value.getSenderId());
assertEquals("love", value.getReactionType());
assertFalse(value.isPostReaction());
assertTrue(value.isCommentReaction());
assertFalse(value.isReplyReaction());
}

@Test
public void feedReactionReplyAdd() {
FeedReactionValue value =
openAndCheckFeedPostBasics("feed-reaction-add-reply", FeedReactionValue.class, ITEM_REACTION, ChangeValue.Verb.ADD);
assertEquals("1234567890321_98735342324352", value.getPostId());
assertEquals("1234567890321_1264545546974600", value.getParentId());
assertEquals("1234567890321_1357555177673636", value.getCommentId());
assertEquals("1234567890321", value.getSenderId());
assertEquals("like", value.getReactionType());
assertFalse(value.isPostReaction());
assertTrue(value.isCommentReaction());
assertTrue(value.isReplyReaction());
}

@Test
Expand Down
24 changes: 24 additions & 0 deletions source/test/resources/json/webhooks/feed-reaction-add-comment.json
@@ -0,0 +1,24 @@
{
"object": "page",
"entry": [
{
"id": "1234567890321",
"time": 1449135003,
"changes": [
{
"field": "feed",
"value": {
"created_time": 1475578854,
"item": "reaction",
"post_id": "1234567890321_98735342324352",
"parent_id": "1234567890321_98735342324352",
"comment_id": "1234567890321_1264545546974600",
"verb": "add",
"reaction_type": "love",
"sender_id": 1234567890321
}
}
]
}
]
}
24 changes: 24 additions & 0 deletions source/test/resources/json/webhooks/feed-reaction-add-reply.json
@@ -0,0 +1,24 @@
{
"object": "page",
"entry": [
{
"id": "1234567890321",
"time": 1449135003,
"changes": [
{
"field": "feed",
"value": {
"created_time": 1475578854,
"item": "reaction",
"post_id": "1234567890321_98735342324352",
"parent_id": "1234567890321_1264545546974600",
"comment_id": "1234567890321_1357555177673636",
"verb": "add",
"reaction_type": "like",
"sender_id": 1234567890321
}
}
]
}
]
}
46 changes: 22 additions & 24 deletions source/test/resources/json/webhooks/feed-reaction-add.json
@@ -1,25 +1,23 @@
{
"object": "page",
"entry": [
{
"id": "1234567890321",
"time": 1449135003,
"changes": [
{
"field": "feed",
"value": {
"created_time": 1475578854,
"item": "reaction",
"post_id": "1234567890321_98735342324352",
"parent_id": "1234567890321_901097836652708",
"verb": "add",
"reaction_type": "love",
"sender_id": 1234567890321
}
}
]
}
]
}


"object": "page",
"entry": [
{
"id": "1234567890321",
"time": 1449135003,
"changes": [
{
"field": "feed",
"value": {
"created_time": 1475578854,
"item": "reaction",
"post_id": "1234567890321_98735342324352",
"parent_id": "1234567890321_901097836652708",
"verb": "add",
"reaction_type": "love",
"sender_id": 1234567890321
}
}
]
}
]
}
42 changes: 21 additions & 21 deletions source/test/resources/json/webhooks/feed-reaction-edit.json
@@ -1,25 +1,25 @@
{
"object": "page",
"entry": [
{
"id": "1234567890321",
"time": 1449135003,
"changes": [
{
"field": "feed",
"value": {
"reaction_type": "wow",
"created_time": 1475578854,
"item": "reaction",
"post_id": "1234567890321_98735342324352",
"parent_id": "1234567890321_901097836652708",
"verb": "edit",
"sender_id": 1234567890321
}
}
]
}
]
"object": "page",
"entry": [
{
"id": "1234567890321",
"time": 1449135003,
"changes": [
{
"field": "feed",
"value": {
"reaction_type": "wow",
"created_time": 1475578854,
"item": "reaction",
"post_id": "1234567890321_98735342324352",
"parent_id": "1234567890321_901097836652708",
"verb": "edit",
"sender_id": 1234567890321
}
}
]
}
]
}


42 changes: 21 additions & 21 deletions source/test/resources/json/webhooks/feed-reaction-remove.json
@@ -1,25 +1,25 @@
{
"object": "page",
"entry": [
{
"id": "1234567890321",
"time": 1449135003,
"changes": [
{
"field": "feed",
"value": {
"reaction_type": "wow",
"created_time": 1475578854,
"item": "reaction",
"post_id": "1234567890321_98735342324352",
"parent_id": "1234567890321_901097836652708",
"verb": "remove",
"sender_id": 1234567890321
}
}
]
}
]
"object": "page",
"entry": [
{
"id": "1234567890321",
"time": 1449135003,
"changes": [
{
"field": "feed",
"value": {
"reaction_type": "wow",
"created_time": 1475578854,
"item": "reaction",
"post_id": "1234567890321_98735342324352",
"parent_id": "1234567890321_901097836652708",
"verb": "remove",
"sender_id": 1234567890321
}
}
]
}
]
}


0 comments on commit c6c1d39

Please sign in to comment.