Skip to content

Commit

Permalink
Issue #1120 - message attachment convenience method added
Browse files Browse the repository at this point in the history
  • Loading branch information
nbartels committed Feb 3, 2021
1 parent 9798d73 commit 03ae608
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/main/lombok/com/restfb/types/Message.java
Expand Up @@ -227,6 +227,18 @@ public boolean isVideo() {
return null != videoData;
}

/**
* returns if the attachment is a placeholder for the real
* attachment, that is not accessible via API due to privacy rules in Europe
*
* check <a href="https://developers.facebook.com/docs/messenger-platform/europe-updates">at Facebook</a>
*
* @return true if not accessible in the EU
*/
public boolean isRemovedInEurope() {
return "1234".equals(getId());
}

}

/**
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/com/restfb/types/MessageTest.java
Expand Up @@ -22,8 +22,7 @@
package com.restfb.types;

import static com.restfb.testutils.RestfbAssertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;

import java.util.List;

Expand Down Expand Up @@ -87,4 +86,12 @@ void messagesWithSticker() {
assertNotNull(exampleMessage);
assertEquals("https://scontent.xx.fbcdn.net/sticker.png", exampleMessage.getSticker());
}

@Test
void messageWithRemovedAttachment() {
Message exampleMessage = createJsonMapper().toJavaObject(jsonFromClasspath("v7_0/message-eu"), Message.class);
assertNotNull(exampleMessage);
Message.Attachment attachment = exampleMessage.getAttachments().get(0);
assertTrue(attachment.isRemovedInEurope());
}
}
11 changes: 11 additions & 0 deletions src/test/resources/json/v7_0/message-eu.json
@@ -0,0 +1,11 @@
{
"attachments": {
"data": [
{
"id": "1234",
"name": "Media not available due to new privacy rules in Europe. See developer documentation for more info"
}
]
},
"id": "m_mid.12345678900:3911138c1ded9ef216"
}

0 comments on commit 03ae608

Please sign in to comment.